|
8 | 8 | "fmt" |
9 | 9 |
|
10 | 10 | gdterrors "github.com/gdt-dev/gdt/errors" |
| 11 | + "gopkg.in/yaml.v3" |
11 | 12 | ) |
12 | 13 |
|
13 | 14 | var ( |
@@ -78,32 +79,51 @@ var ( |
78 | 79 |
|
79 | 80 | // UnsupportedJSONSchemaReference returns ErrUnsupportedJSONSchemaReference for |
80 | 81 | // a supplied URL. |
81 | | -func UnsupportedJSONSchemaReference(url string) error { |
82 | | - return fmt.Errorf("%w: %s", ErrUnsupportedJSONSchemaReference, url) |
| 82 | +func UnsupportedJSONSchemaReference(url string, node *yaml.Node) error { |
| 83 | + return fmt.Errorf( |
| 84 | + "%w: %s at line %d, column %d", |
| 85 | + ErrUnsupportedJSONSchemaReference, url, node.Line, node.Column, |
| 86 | + ) |
83 | 87 | } |
84 | 88 |
|
85 | 89 | // JSONSchemaFileNotFound returns ErrJSONSchemaFileNotFound for a supplied |
86 | 90 | // path. |
87 | | -func JSONSchemaFileNotFound(path string) error { |
88 | | - return fmt.Errorf("%w: %s", ErrJSONSchemaFileNotFound, path) |
| 91 | +func JSONSchemaFileNotFound(path string, node *yaml.Node) error { |
| 92 | + return fmt.Errorf( |
| 93 | + "%w: %s at line %d, column %d", |
| 94 | + ErrJSONSchemaFileNotFound, path, node.Line, node.Column, |
| 95 | + ) |
89 | 96 | } |
90 | 97 |
|
91 | 98 | // JSONUnmarshalError returns an ErrFailure when JSON content cannot be |
92 | 99 | // decoded. |
93 | | -func JSONUnmarshalError(err error) error { |
94 | | - return fmt.Errorf("%w: %s", ErrJSONUnmarshalError, err) |
| 100 | +func JSONUnmarshalError(err error, node *yaml.Node) error { |
| 101 | + if node != nil { |
| 102 | + return fmt.Errorf( |
| 103 | + "%w: %s at line %d, column %d", |
| 104 | + ErrJSONUnmarshalError, err, node.Line, node.Column, |
| 105 | + ) |
| 106 | + } else { |
| 107 | + return fmt.Errorf("%w: %s", ErrJSONUnmarshalError, err) |
| 108 | + } |
95 | 109 | } |
96 | 110 |
|
97 | 111 | // JSONPathInvalid returns an ErrParse when a JSONPath expression could not be |
98 | 112 | // parsed. |
99 | | -func JSONPathInvalid(path string, err error) error { |
100 | | - return fmt.Errorf("%w: %s: %s", ErrJSONPathInvalid, path, err) |
| 113 | +func JSONPathInvalid(path string, err error, node *yaml.Node) error { |
| 114 | + return fmt.Errorf( |
| 115 | + "%w: %s: %s at line %d, column %d", |
| 116 | + ErrJSONPathInvalid, path, err, node.Line, node.Column, |
| 117 | + ) |
101 | 118 | } |
102 | 119 |
|
103 | 120 | // JSONPathInvalidNoRoot returns an ErrJSONPathInvalidNoRoot when a JSONPath |
104 | 121 | // expression does not start with '$'. |
105 | | -func JSONPathInvalidNoRoot(path string) error { |
106 | | - return fmt.Errorf("%w: %s", ErrJSONPathInvalidNoRoot, path) |
| 122 | +func JSONPathInvalidNoRoot(path string, node *yaml.Node) error { |
| 123 | + return fmt.Errorf( |
| 124 | + "%w: %s at line %d, column %d", |
| 125 | + ErrJSONPathInvalidNoRoot, path, node.Line, node.Column, |
| 126 | + ) |
107 | 127 | } |
108 | 128 |
|
109 | 129 | // JSONPathNotFound returns an ErrFailure when a JSONPath expression could not |
|
0 commit comments