{"record":{"id":"9a6c0eaa27422087","repo":"antonmedv/fx","slug":"error-from-utils-unquote-it-key-unquoting-the-ob","errorCode":null,"errorMessage":"<error from utils.Unquote(it.Key) unquoting the object key> (panic(err))","messagePattern":"<error from utils\\.Unquote\\(it\\.Key\\) unquoting the object key> \\(panic\\(err\\)\\)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/jsonx/to_value.go","lineNumber":58,"sourceCode":"\t\t\tpanic(err)\n\t\t}\n\t\treturn vm.ToValue(unquoted)\n\n\tcase Object:\n\t\tobj := vm.NewObject()\n\n\t\tif n.HasChildren() {\n\t\t\tit := n\n\t\t\tif it.IsCollapsed() {\n\t\t\t\tit = it.Collapsed\n\t\t\t} else {\n\t\t\t\tit = it.Next\n\t\t\t}\n\n\t\t\tfor it != nil && it != n.End {\n\t\t\t\tunquotedKey, err := utils.Unquote(it.Key)\n\t\t\t\tif err != nil {\n\t\t\t\t\tpanic(err)\n\t\t\t\t}\n\n\t\t\t\terr = obj.Set(unquotedKey, it.ToValue(vm))\n\t\t\t\tif err != nil {\n\t\t\t\t\tpanic(err)\n\t\t\t\t}\n\n\t\t\t\tif it.HasChildren() {\n\t\t\t\t\tit = it.End.Next\n\t\t\t\t} else {\n\t\t\t\t\tit = it.Next\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn obj\n\n\tcase Array:","sourceCodeStart":40,"sourceCodeEnd":76,"githubUrl":"https://github.com/antonmedv/fx/blob/4f31cd3a0c5d66f1b4290a2719bab14a5cee8ebe/internal/jsonx/to_value.go#L40-L76","documentation":"When converting an Object node, ToValue unquotes each member key with utils.Unquote before setting it on the goja object. If a key is not a valid quoted string (bad escapes, missing quotes), Unquote's error is panicked. Keys in JSON must be valid string literals; this fires when a key node's raw text violates that.","triggerScenarios":"ToValue on an Object whose member Key fields contain invalid escapes (e.g. 'C:\\dir' unescaped) or are not properly quoted string literals.","commonSituations":"Documents generated by string concatenation without escaping, keys copied from non-JSON sources, hand-assembled nodes in tests or tooling.","solutions":["Fix the offending key in the source: escape backslashes and quotes properly.","Re-parse the original document so the parser normalizes keys.","When generating JSON programmatically, always marshal keys through a JSON encoder.","Recover the panic in the conversion wrapper and report which key failed."],"exampleFix":"// before\n{\"C:\\dir\": 1}\n// after\n{\"C:\\\\dir\": 1}","handlingStrategy":"try-catch","validationCode":"var dummy map[string]json.RawMessage\nif err := json.Unmarshal(data, &dummy); err != nil {\n    return fmt.Errorf(\"input has malformed keys: %w\", err)\n}","typeGuard":"func isValidObjectNode(n *jsonx.Node) bool {\n    if n.Kind != jsonx.Object {\n        return false\n    }\n    for it := n.Next; it != nil && it != n.End; it = it.Next {\n        if it.Key != \"\" {\n            var s string\n            if json.Unmarshal([]byte(it.Key), &s) != nil {\n                return false\n            }\n        }\n    }\n    return true\n}","tryCatchPattern":"func safeObjectToValue(n *jsonx.Node, vm *goja.Runtime) (v goja.Value, err error) {\n    defer func() {\n        if r := recover(); r != nil {\n            err = fmt.Errorf(\"object conversion failed (bad key?): %v\", r)\n        }\n    }()\n    return n.ToValue(vm), nil\n}","preventionTips":["Marshal keys through encoding/json when generating documents.","Round-trip unmarshal into map[string]json.RawMessage to validate keys.","Escape backslashes and quotes in keys from external sources.","Recover panics and log the raw key text for diagnosis."],"tags":["json","object","key","unquote","panic"],"backgroundTag":"invalid-escape-sequence","analyzedSha":"4f31cd3a0c5d66f1b4290a2719bab14a5cee8ebe","analyzedAt":"2026-09-02T02:17:47.344Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T06:17:21.866Z"}