File: error.go

package info (click to toggle)
dasel 2.8.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 5,844 kB
  • sloc: sh: 53; python: 21; makefile: 21; xml: 20
file content (107 lines) | stat: -rw-r--r-- 3,071 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
package dasel

import (
	"errors"
	"fmt"
	"reflect"
)

// ErrMissingPreviousNode is returned when findValue doesn't have access to the previous node.
var ErrMissingPreviousNode = errors.New("missing previous node")

// UnknownComparisonOperatorErr is returned when
type UnknownComparisonOperatorErr struct {
	Operator string
}

// Error returns the error message.
func (e UnknownComparisonOperatorErr) Error() string {
	return fmt.Sprintf("unknown comparison operator: %s", e.Operator)
}

// Is implements the errors interface, so the errors.Is() function can be used.
func (e UnknownComparisonOperatorErr) Is(err error) bool {
	_, ok := err.(*UnknownComparisonOperatorErr)
	return ok
}

// InvalidIndexErr is returned when a selector targets an index that does not exist.
type InvalidIndexErr struct {
	Index string
}

// Error returns the error message.
func (e InvalidIndexErr) Error() string {
	return fmt.Sprintf("invalid index: %s", e.Index)
}

// Is implements the errors interface, so the errors.Is() function can be used.
func (e InvalidIndexErr) Is(err error) bool {
	_, ok := err.(*InvalidIndexErr)
	return ok
}

// UnsupportedSelector is returned when a specific selector type is used in the wrong context.
type UnsupportedSelector struct {
	Selector string
}

// Error returns the error message.
func (e UnsupportedSelector) Error() string {
	return fmt.Sprintf("selector is not supported here: %s", e.Selector)
}

// Is implements the errors interface, so the errors.Is() function can be used.
func (e UnsupportedSelector) Is(err error) bool {
	_, ok := err.(*UnsupportedSelector)
	return ok
}

// ValueNotFound is returned when a selector string cannot be fully resolved.
type ValueNotFound struct {
	Selector      string
	PreviousValue reflect.Value
}

// Error returns the error message.
func (e ValueNotFound) Error() string {
	return fmt.Sprintf("no value found for selector: %s: %v", e.Selector, e.PreviousValue)
}

// Is implements the errors interface, so the errors.Is() function can be used.
func (e ValueNotFound) Is(err error) bool {
	_, ok := err.(*ValueNotFound)
	return ok
}

// UnexpectedPreviousNilValue is returned when the previous node contains a nil value.
type UnexpectedPreviousNilValue struct {
	Selector string
}

// Error returns the error message.
func (e UnexpectedPreviousNilValue) Error() string {
	return fmt.Sprintf("previous value is nil: %s", e.Selector)
}

// Is implements the errors interface, so the errors.Is() function can be used.
func (e UnexpectedPreviousNilValue) Is(err error) bool {
	_, ok := err.(*UnexpectedPreviousNilValue)
	return ok
}

// UnhandledCheckType is returned when the a check doesn't know how to deal with the given type
type UnhandledCheckType struct {
	Value interface{}
}

// Error returns the error message.
func (e UnhandledCheckType) Error() string {
	return fmt.Sprintf("unhandled check type: %T", e.Value)
}

// Is implements the errors interface, so the errors.Is() function can be used.
func (e UnhandledCheckType) Is(err error) bool {
	_, ok := err.(*UnhandledCheckType)
	return ok
}