errors

package
v2.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 30, 2025 License: MIT Imports: 1 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ErrorBasicRuntime

type ErrorBasicRuntime struct {
	// contains filtered or unexported fields
}

ErrorBasicRuntime is a basic runtime error structure

func NewErrorBasicRuntime added in v2.2.0

func NewErrorBasicRuntime(path string, remainingPathLen int) ErrorBasicRuntime

func (*ErrorBasicRuntime) GetPath

func (e *ErrorBasicRuntime) GetPath() string

func (*ErrorBasicRuntime) GetRemainingPathLen

func (e *ErrorBasicRuntime) GetRemainingPathLen() int

type ErrorFunctionFailed

type ErrorFunctionFailed struct {
	*ErrorBasicRuntime
	Err error
}

ErrorFunctionFailed represents the error that function execution failed in the JSONPath.

Example
config := config.Config{}
config.SetFilterFunction(`invalid`, func(param any) (any, error) {
	return nil, fmt.Errorf(`invalid function executed`)
})
jsonPath, srcJSON := `$.invalid()`, `{}`
var src any
json.Unmarshal([]byte(srcJSON), &src)
output, err := jsonpath.Retrieve(jsonPath, src, config)
switch err.(type) {
case errors.ErrorFunctionFailed:
	fmt.Printf(`type: %v, value: %v`, reflect.TypeOf(err), err)
	return
}
outputJSON, _ := json.Marshal(output)
fmt.Println(string(outputJSON))
Output:

type: errors.ErrorFunctionFailed, value: function failed (path=.invalid(), error=invalid function executed)

func NewErrorFunctionFailed

func NewErrorFunctionFailed(path string, remainingPathLen int, err error) ErrorFunctionFailed

func (ErrorFunctionFailed) Error

func (e ErrorFunctionFailed) Error() string

type ErrorFunctionNotFound

type ErrorFunctionNotFound struct {
	Function string
}

ErrorFunctionNotFound represents the error that the function specified in the JSONPath is not found.

Example
jsonPath, srcJSON := `$.unknown()`, `{}`
var src any
json.Unmarshal([]byte(srcJSON), &src)
output, err := jsonpath.Retrieve(jsonPath, src)
switch err.(type) {
case errors.ErrorFunctionNotFound:
	fmt.Printf(`type: %v, value: %v`, reflect.TypeOf(err), err)
	return
}
outputJSON, _ := json.Marshal(output)
fmt.Println(string(outputJSON))
Output:

type: errors.ErrorFunctionNotFound, value: function not found (path=.unknown())

func NewErrorFunctionNotFound

func NewErrorFunctionNotFound(function string) ErrorFunctionNotFound

func (ErrorFunctionNotFound) Error

func (e ErrorFunctionNotFound) Error() string

type ErrorInvalidArgument

type ErrorInvalidArgument struct {
	ArgumentName string
	Err          error
}

ErrorInvalidArgument represents the error that argument specified in the JSONPath is treated as the invalid error in Go syntax.

Example
jsonPath, srcJSON := `$[?(1.0.0>0)]`, `{}`
var src any
json.Unmarshal([]byte(srcJSON), &src)
output, err := jsonpath.Retrieve(jsonPath, src)
switch err.(type) {
case errors.ErrorInvalidArgument:
	fmt.Printf(`type: %v, value: %v`, reflect.TypeOf(err), err)
	return
}
outputJSON, _ := json.Marshal(output)
fmt.Println(string(outputJSON))
Output:

type: errors.ErrorInvalidArgument, value: invalid argument (argument=1.0.0, error=strconv.ParseFloat: parsing "1.0.0": invalid syntax)

func NewErrorInvalidArgument

func NewErrorInvalidArgument(argument string, err error) ErrorInvalidArgument

func (ErrorInvalidArgument) Error

func (e ErrorInvalidArgument) Error() string

type ErrorInvalidSyntax

type ErrorInvalidSyntax struct {
	Position int
	Reason   string
	Near     string
}

ErrorInvalidSyntax represents the error that have syntax error in the JSONPath.

Example
jsonPath, srcJSON := `$.`, `{}`
var src any
json.Unmarshal([]byte(srcJSON), &src)
output, err := jsonpath.Retrieve(jsonPath, src)
switch err.(type) {
case errors.ErrorInvalidSyntax:
	fmt.Printf(`type: %v, value: %v`, reflect.TypeOf(err), err)
	return
}
outputJSON, _ := json.Marshal(output)
fmt.Println(string(outputJSON))
Output:

type: errors.ErrorInvalidSyntax, value: invalid syntax (position=1, reason=unrecognized input, near=.)

func NewErrorInvalidSyntax

func NewErrorInvalidSyntax(position int, reason string, near string) ErrorInvalidSyntax

func (ErrorInvalidSyntax) Error

func (e ErrorInvalidSyntax) Error() string

type ErrorMemberNotExist

type ErrorMemberNotExist struct {
	*ErrorBasicRuntime
}

ErrorMemberNotExist represents the error that the member specified in the JSONPath did not exist in the JSON object.

Example
jsonPath, srcJSON := `$.none`, `{}`
var src any
json.Unmarshal([]byte(srcJSON), &src)
output, err := jsonpath.Retrieve(jsonPath, src)
switch err.(type) {
case errors.ErrorMemberNotExist:
	fmt.Printf(`type: %v, value: %v`, reflect.TypeOf(err), err)
	return
}
outputJSON, _ := json.Marshal(output)
fmt.Println(string(outputJSON))
Output:

type: errors.ErrorMemberNotExist, value: member did not exist (path=.none)

func NewErrorMemberNotExist

func NewErrorMemberNotExist(errBasicRuntime *ErrorBasicRuntime) ErrorMemberNotExist

func (ErrorMemberNotExist) Error

func (e ErrorMemberNotExist) Error() string

type ErrorNotSupported

type ErrorNotSupported struct {
	Feature string
	Path    string
}

ErrorNotSupported represents the error that the unsupported syntaxes specified in the JSONPath.

Example
jsonPath, srcJSON := `$[(command)]`, `{}`
var src any
json.Unmarshal([]byte(srcJSON), &src)
output, err := jsonpath.Retrieve(jsonPath, src)
switch err.(type) {
case errors.ErrorNotSupported:
	fmt.Printf(`type: %v, value: %v`, reflect.TypeOf(err), err)
	return
}
outputJSON, _ := json.Marshal(output)
fmt.Println(string(outputJSON))
Output:

type: errors.ErrorNotSupported, value: not supported (path=[(command)], feature=script)

func NewErrorNotSupported

func NewErrorNotSupported(feature string, path string) ErrorNotSupported

func (ErrorNotSupported) Error

func (e ErrorNotSupported) Error() string

type ErrorRuntime

type ErrorRuntime interface {
	GetPath() string
	GetRemainingPathLen() int
	Error() string
}

type ErrorTypeUnmatched

type ErrorTypeUnmatched struct {
	*ErrorBasicRuntime
	ExpectedType string
	FoundType    string
}

ErrorTypeUnmatched represents the error that the node type specified in the JSONPath did not exist in the JSON object.

Example
jsonPath, srcJSON := `$.a`, `[]`
var src any
json.Unmarshal([]byte(srcJSON), &src)
output, err := jsonpath.Retrieve(jsonPath, src)
switch err.(type) {
case errors.ErrorTypeUnmatched:
	fmt.Printf(`type: %v, value: %v`, reflect.TypeOf(err), err)
	return
}
outputJSON, _ := json.Marshal(output)
fmt.Println(string(outputJSON))
Output:

type: errors.ErrorTypeUnmatched, value: type unmatched (path=.a, expected=object, found=[]interface {})

func NewErrorTypeUnmatched

func NewErrorTypeUnmatched(errBasicRuntime *ErrorBasicRuntime, expected string, found string) ErrorTypeUnmatched

func (ErrorTypeUnmatched) Error

func (e ErrorTypeUnmatched) Error() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL