Documentation
¶
Overview ¶
Package errors provides structured error types for jsonlogic2sql transpilation.
Index ¶
- func BuildArrayPath(parent string, index int) string
- func BuildPath(parent, operator string, index int) string
- type ErrorCode
- type TranspileError
- func New(code ErrorCode, operator, path, message string) *TranspileError
- func NewArrayNotAllowed(path string) *TranspileError
- func NewFieldNotInSchema(field, path string) *TranspileError
- func NewInsufficientArgs(operator, path string, required, got int) *TranspileError
- func NewInvalidArgument(operator, path string, argIndex int, cause error) *TranspileError
- func NewInvalidEnumValue(field, path, value string, allowed []string) *TranspileError
- func NewInvalidFieldType(operator, path, field, fieldType, expectedType string) *TranspileError
- func NewInvalidJSON(cause error) *TranspileError
- func NewMultipleKeys(path string) *TranspileError
- func NewOperatorRequiresArray(operator, path string) *TranspileError
- func NewPrimitiveNotAllowed(path string) *TranspileError
- func NewTooManyArgs(operator, path string, maxArgs, got int) *TranspileError
- func NewTypeMismatch(operator, path, expected, got string) *TranspileError
- func NewUnsupportedOperator(operator, path string) *TranspileError
- func NewValidationError(cause error) *TranspileError
- func Wrap(code ErrorCode, operator, path, message string, cause error) *TranspileError
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BuildArrayPath ¶
BuildArrayPath constructs a JSONPath string for an array index.
Types ¶
type ErrorCode ¶
type ErrorCode string
ErrorCode represents a specific error condition. Codes are organized by category:
- E001-E099: Structural/validation errors
- E100-E199: Operator-specific errors
- E200-E299: Type/schema errors
- E300-E399: Argument errors
const ( // ErrInvalidExpression indicates the expression type is not valid JSON Logic. ErrInvalidExpression ErrorCode = "E001" // ErrEmptyArray indicates an array cannot be empty in this context. ErrEmptyArray ErrorCode = "E002" // ErrMultipleKeys indicates an operator object must have exactly one key. ErrMultipleKeys ErrorCode = "E003" // ErrPrimitiveNotAllowed indicates primitive values are not allowed in this context. ErrPrimitiveNotAllowed ErrorCode = "E004" // ErrArrayNotAllowed indicates arrays are not allowed in this context. ErrArrayNotAllowed ErrorCode = "E005" // ErrValidation indicates a general validation error. ErrValidation ErrorCode = "E006" // ErrInvalidJSON indicates the input is not valid JSON. ErrInvalidJSON ErrorCode = "E007" )
Structural/validation error codes (E001-E099).
const ( // ErrUnsupportedOperator indicates the operator is not recognized. ErrUnsupportedOperator ErrorCode = "E100" // ErrOperatorRequiresArray indicates the operator requires array arguments. ErrOperatorRequiresArray ErrorCode = "E101" // ErrCustomOperatorFailed indicates a custom operator returned an error. ErrCustomOperatorFailed ErrorCode = "E102" )
Operator-specific error codes (E100-E199).
const ( // ErrTypeMismatch indicates a type mismatch in the expression. ErrTypeMismatch ErrorCode = "E200" // ErrFieldNotInSchema indicates the field is not defined in the schema. ErrFieldNotInSchema ErrorCode = "E201" // ErrInvalidFieldType indicates the field type is incompatible with the operation. ErrInvalidFieldType ErrorCode = "E202" // ErrInvalidEnumValue indicates the value is not valid for the enum field. ErrInvalidEnumValue ErrorCode = "E203" )
Type/schema error codes (E200-E299).
const ( // ErrInsufficientArgs indicates the operator requires more arguments. ErrInsufficientArgs ErrorCode = "E300" // ErrTooManyArgs indicates the operator received too many arguments. ErrTooManyArgs ErrorCode = "E301" // ErrInvalidArgument indicates an argument is invalid. ErrInvalidArgument ErrorCode = "E302" // ErrInvalidArgType indicates an argument has the wrong type. ErrInvalidArgType ErrorCode = "E303" // ErrInvalidDefaultValue indicates the default value is invalid. ErrInvalidDefaultValue ErrorCode = "E304" // ErrUnreferencedPlaceholder indicates a collected bind parameter has no // matching placeholder in the generated SQL, typically because a custom // operator dropped an argument. ErrUnreferencedPlaceholder ErrorCode = "E350" )
Argument error codes (E300-E399).
type TranspileError ¶
type TranspileError struct {
// Code is the error code for programmatic handling.
Code ErrorCode
// Operator is the operator that caused the error (may be empty for structural errors).
Operator string
// Path is the JSONPath to the error location (e.g., "$.and[0].>").
Path string
// Message is the human-readable error message.
Message string
// Cause is the underlying error, if any.
Cause error
}
TranspileError represents an error during JSONLogic transpilation. It implements the error interface and provides structured context for debugging.
func New ¶
func New(code ErrorCode, operator, path, message string) *TranspileError
New creates a new TranspileError with the given parameters.
func NewArrayNotAllowed ¶
func NewArrayNotAllowed(path string) *TranspileError
NewArrayNotAllowed creates an error when arrays are not allowed at top level.
func NewFieldNotInSchema ¶
func NewFieldNotInSchema(field, path string) *TranspileError
NewFieldNotInSchema creates an error when a field is not in the schema.
func NewInsufficientArgs ¶
func NewInsufficientArgs(operator, path string, required, got int) *TranspileError
NewInsufficientArgs creates an error for insufficient arguments.
func NewInvalidArgument ¶
func NewInvalidArgument(operator, path string, argIndex int, cause error) *TranspileError
NewInvalidArgument creates an error for an invalid argument at a specific index.
func NewInvalidEnumValue ¶
func NewInvalidEnumValue(field, path, value string, allowed []string) *TranspileError
NewInvalidEnumValue creates an error for an invalid enum value.
func NewInvalidFieldType ¶
func NewInvalidFieldType(operator, path, field, fieldType, expectedType string) *TranspileError
NewInvalidFieldType creates an error for an incompatible field type.
func NewInvalidJSON ¶
func NewInvalidJSON(cause error) *TranspileError
NewInvalidJSON creates an error for invalid JSON input.
func NewMultipleKeys ¶
func NewMultipleKeys(path string) *TranspileError
NewMultipleKeys creates an error when an operator object has multiple keys.
func NewOperatorRequiresArray ¶
func NewOperatorRequiresArray(operator, path string) *TranspileError
NewOperatorRequiresArray creates an error when an operator needs array arguments.
func NewPrimitiveNotAllowed ¶
func NewPrimitiveNotAllowed(path string) *TranspileError
NewPrimitiveNotAllowed creates an error when primitives are not allowed.
func NewTooManyArgs ¶
func NewTooManyArgs(operator, path string, maxArgs, got int) *TranspileError
NewTooManyArgs creates an error for too many arguments.
func NewTypeMismatch ¶
func NewTypeMismatch(operator, path, expected, got string) *TranspileError
NewTypeMismatch creates an error for a type mismatch.
func NewUnsupportedOperator ¶
func NewUnsupportedOperator(operator, path string) *TranspileError
NewUnsupportedOperator creates an error for an unsupported operator.
func NewValidationError ¶
func NewValidationError(cause error) *TranspileError
NewValidationError wraps a validation error from the validator package.
func Wrap ¶
func Wrap(code ErrorCode, operator, path, message string, cause error) *TranspileError
Wrap creates a new TranspileError wrapping an underlying error.
func (*TranspileError) Error ¶
func (e *TranspileError) Error() string
Error implements the error interface.
func (*TranspileError) Unwrap ¶
func (e *TranspileError) Unwrap() error
Unwrap returns the underlying error for errors.Is/As support.
func (*TranspileError) WithOperator ¶
func (e *TranspileError) WithOperator(operator string) *TranspileError
WithOperator returns a copy of the error with the operator updated.
func (*TranspileError) WithPath ¶
func (e *TranspileError) WithPath(path string) *TranspileError
WithPath returns a copy of the error with the path updated. This is useful for adding path context as errors bubble up.