{"record":{"id":"c2cacd8953bbaae7","repo":"hasura/graphql-engine","slug":"jsonparser-w","errorCode":null,"errorMessage":"jsonparser: %w","messagePattern":"jsonparser: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cli/internal/metadatautil/sources.go","lineNumber":48,"sourceCode":"\tvar kind *string\n\n\t_, err = jsonparser.ArrayEach(\n\t\tmetadata,\n\t\tfunc(value []byte, dataType jsonparser.ValueType, offset int, err error) {\n\t\t\tvar v string\n\n\t\t\tv, _ = jsonparser.GetString(value, \"name\")\n\t\t\tif v == sourceName {\n\t\t\t\tk, _ := jsonparser.GetString(value, \"kind\")\n\t\t\t\tif len(k) > 0 {\n\t\t\t\t\tkind = &k\n\t\t\t\t}\n\t\t\t}\n\t\t},\n\t\t\"sources\",\n\t)\n\tif err != nil {\n\t\treturn nil, internalerrors.E(op, fmt.Errorf(\"jsonparser: %w\", err))\n\t}\n\n\tif kind != nil {\n\t\treturn (*hasura.SourceKind)(kind), nil\n\t}\n\n\treturn nil, nil\n}\n\nfunc GetSources(exportMetadata func() (io.Reader, error)) ([]string, error) {\n\tvar op internalerrors.Op = \"metadatautil.GetSources\"\n\n\tmetadataReader, err := exportMetadata()\n\tif err != nil {\n\t\treturn nil, internalerrors.E(op, err)\n\t}\n\n\tmetadata, err := io.ReadAll(metadataReader)","sourceCodeStart":30,"sourceCodeEnd":66,"githubUrl":"https://github.com/hasura/graphql-engine/blob/724551b9ae87845594ef0408cff0e50eb6c90dc5/cli/internal/metadatautil/sources.go#L30-L66","documentation":"This error is returned by metadatautil.GetSourceKind when the underlying jsonparser library fails while walking the 'sources' array of the exported Hasura metadata JSON. It wraps the jsonparser error verbatim, so the root cause (malformed JSON, wrong type at a key, or key not found) is visible only in the wrapped message. It indicates the metadata export the CLI fed in could not be parsed at the expected shape.","triggerScenarios":"Calling GetSourceKind(exportMetadata) where exportMetadata returns a reader whose JSON is invalid, or where the 'sources' key exists but an element's 'kind' field is not a string (jsonparser.ArrayEach / GetString each error). Typical with corrupt metadata files or an endpoint returning HTML/error bodies instead of JSON.","commonSituations":"Metadata exported from an incompatible Hasura version, a truncated metadata.json, or an API endpoint behind a proxy returning a login page. Also occurs when migrating projects whose metadata structure changed between CLI versions.","solutions":["Inspect the full wrapped message: if it says 'Key path not found' the metadata has no sources; if 'cannot unmarshal' the JSON type at sources/kind is wrong","Print/export the metadata (hasura metadata export) and validate it with jq . to confirm it is well-formed JSON","Verify the Hasura server version matches the CLI version (metadata formats differ between v1/v2/v3)","If the reader comes from an HTTP call, check the server actually returned JSON (status code, content-type)"],"exampleFix":"// before\nkind, err := metadatautil.GetSourceKind(exportMetadata)\nif err != nil { return err }\n\n// after\nkind, err := metadatautil.GetSourceKind(exportMetadata)\nif err != nil {\n    // surface the wrapped jsonparser cause and the raw metadata for debugging\n    return fmt.Errorf(\"getting source kind (is metadata valid JSON?): %w\", err)\n}","handlingStrategy":"validation","validationCode":"r, err := exportMetadata()\nif err != nil { return err }\nraw, _ := io.ReadAll(r)\nif !json.Valid(raw) { return errors.New(\"metadata is not valid JSON\") }","typeGuard":"func isParsableMetadata(r io.Reader) bool {\n    b, err := io.ReadAll(r)\n    return err == nil && json.Valid(b)\n}","tryCatchPattern":"if err != nil {\n    return fmt.Errorf(\"getting source kind: %w\", err) // inspect wrapped jsonparser cause\n}","preventionTips":["Validate exported metadata with json.Valid before parsing","Keep CLI version aligned with the Hasura server version","Log the raw metadata body when parse errors occur"],"tags":["go","hasura-cli","jsonparser","metadata-parsing"],"backgroundTag":"json-parsing-error","analyzedSha":"724551b9ae87845594ef0408cff0e50eb6c90dc5","analyzedAt":"2026-08-28T07:32:55.105Z","schemaVersion":2},"datasetVersion":"2026-08-28T11:17:15.048Z"}