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

  1. Validate the JSON document (json.Valid) before processing
  2. Check errors.Is(err, jsonx.ErrInvalid) and fall back to full json.Unmarshal on the complete document
  3. 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

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


AI-assisted analysis of kataras/iris@7bedaf55a0 (2026-08-30). Data as JSON: /api/errors/11ab52e17ad663dc. Report an issue: GitHub.