{"record":{"id":"11ab52e17ad663dc","repo":"kataras/iris","slug":"invalid","errorCode":null,"errorMessage":"invalid","messagePattern":"invalid","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"x/jsonx/jsonx.go","lineNumber":14,"sourceCode":"package jsonx\n\nimport (\n\t\"bytes\"\n\t\"errors\"\n)\n\nvar (\n\tquoteLiteral    = '\"'\n\temptyQuoteBytes = []byte(`\"\"`)\n\tnullLiteral     = []byte(\"null\")\n\n\t// ErrInvalid is returned when the value is invalid.\n\tErrInvalid = errors.New(\"invalid\")\n)\n\nfunc isNull(b []byte) bool {\n\treturn len(b) == 0 || bytes.Equal(b, nullLiteral)\n}\n\nfunc trimQuotesFunc(r rune) bool {\n\treturn r == quoteLiteral\n}\n\nfunc trimQuotes(b []byte) []byte {\n\treturn bytes.TrimFunc(b, trimQuotesFunc)\n}\n","sourceCodeStart":1,"sourceCodeEnd":28,"githubUrl":"https://github.com/kataras/iris/blob/7bedaf55a0b64bbb2248a5845a2c60d81a30996a/x/jsonx/jsonx.go#L1-L28","documentation":"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.","triggerScenarios":"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.","commonSituations":"Using jsonx partial-read helpers against documents missing the expected field; feeding truncated or hand-written JSON instead of encoder-produced JSON.","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"],"exampleFix":"// before\nv, err := jsonx.Call(raw, \"user.name\")\nreturn err\n// after\nv, err := jsonx.Call(raw, \"user.name\")\nif errors.Is(err, jsonx.ErrInvalid) {\n    return fmt.Errorf(\"field %q missing in document\", \"user.name\")\n}","handlingStrategy":"type-guard","validationCode":"if !json.Valid(raw) { return errors.New(\"malformed JSON\") }","typeGuard":"func isInvalidJSONValue(err error) bool { return errors.Is(err, jsonx.ErrInvalid) }","tryCatchPattern":"v, err := jsonx.Call(raw, \"user.name\")\nif errors.Is(err, jsonx.ErrInvalid) {\n    return handleMissingField(\"user.name\")\n}\nif err != nil { return err }","preventionTips":["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"],"tags":["json","validation","sentinel-error"],"backgroundTag":"invalid-json-value","analyzedSha":"7bedaf55a0b64bbb2248a5845a2c60d81a30996a","analyzedAt":"2026-08-30T20:38:16.250Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}