kataras/iris · error
invalid
Error message
invalid
What it means
jsonx.ErrInvalid is a sentinel ('invalid') returned when a JSON value is invalid during custom lightweight JSON decoding (jsonx.call) or UnmarshalJSON paths. Per its doc comment it is 'returned when the value is invalid'. Compare with errors.Is(err, jsonx.ErrInvalid) to detect malformed values handled by jsonx helpers.
Source
Thrown at x/jsonx/jsonx.go:14
package jsonx
import (
"bytes"
"errors"
)
var (
quoteLiteral = '"'
emptyQuoteBytes = []byte(`""`)
nullLiteral = []byte("null")
// ErrInvalid is returned when the value is invalid.
ErrInvalid = errors.New("invalid")
)
func isNull(b []byte) bool {
return len(b) == 0 || bytes.Equal(b, nullLiteral)
}
func trimQuotesFunc(r rune) bool {
return r == quoteLiteral
}
func trimQuotes(b []byte) []byte {
return bytes.TrimFunc(b, trimQuotesFunc)
}
View on GitHub (pinned to 7bedaf55a0)
Solutions
- Validate the JSON document (json.Valid) before processing
- Check errors.Is(err, jsonx.ErrInvalid) and fall back to full json.Unmarshal on the complete document
- Ensure the field path/expression used with jsonx helpers exists in the document
Example fix
// before
v, err := jsonx.Call(raw, "user.name")
return err
// after
v, err := jsonx.Call(raw, "user.name")
if errors.Is(err, jsonx.ErrInvalid) {
return fmt.Errorf("field %q missing in document", "user.name")
} Defensive patterns
Strategy: type-guard
Validate before calling
if !json.Valid(raw) { return errors.New("malformed JSON") } Type guard
func isInvalidJSONValue(err error) bool { return errors.Is(err, jsonx.ErrInvalid) } Try / catch
v, err := jsonx.Call(raw, "user.name")
if errors.Is(err, jsonx.ErrInvalid) {
return handleMissingField("user.name")
}
if err != nil { return err } Prevention
- Validate documents with json.Valid before jsonx partial decoding
- Verify field paths exist with a probe decode
- Only feed encoder-produced, well-formed JSON to jsonx helpers
When it happens
Trigger: jsonx.call invoked with an expression/field path that does not resolve to a valid value; UnmarshalJSON of a jsonx wrapper receiving malformed or null-incompatible input.
Common situations: Using jsonx partial-read helpers against documents missing the expected field; feeding truncated or hand-written JSON instead of encoder-produced JSON.
Related errors
- ErrNotFound
- not found
- empty form
- errors joined from param parser: strings.Join(p.errors, "\n"
- parameter is not alphabetical
AI-assisted analysis of kataras/iris@7bedaf55a0 (2026-08-30).
Data as JSON: /api/errors/11ab52e17ad663dc.
Report an issue: GitHub.