{"record":{"id":"4751f9e5760c6f59","repo":"antonmedv/fx","slug":"unsupported-node-kind-d","errorCode":null,"errorMessage":"unsupported node kind %d","messagePattern":"unsupported node kind (.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/jsonx/to_value.go","lineNumber":113,"sourceCode":"\t\t\t}\n\t\t}\n\n\t\treturn vm.NewArray(arr...)\n\n\tcase NaN:\n\t\treturn vm.ToValue(math.NaN())\n\n\tcase Infinity:\n\t\tif n.Value[0] == '-' {\n\t\t\treturn vm.ToValue(math.Inf(-1))\n\t\t}\n\t\treturn vm.ToValue(math.Inf(1))\n\n\tcase Undefined:\n\t\treturn goja.Undefined()\n\n\t}\n\tpanic(fmt.Sprintf(\"unsupported node kind %d\", n.Kind))\n}\n\n// maxSafeInt is 2^53 - 1, the largest integer JS can represent exactly.\nconst maxSafeInt = 1<<53 - 1\n\n// minSafeInt is -(2^53 - 1).\nconst minSafeInt = -maxSafeInt\n\n// ParseNumber parses a number from a string as int64 or *big.Int.\nfunc ParseNumber(s string) (interface{}, bool) {\n\tbi := new(big.Int)\n\tif _, ok := bi.SetString(s, 10); !ok {\n\t\treturn nil, false\n\t}\n\n\t// Quickly reject values whose bit-length exceeds 54 (i.e. >= 2^53).\n\t// big.Int.BitLen returns the length of the absolute value in bits.\n\tif bi.BitLen() <= 53 {","sourceCodeStart":95,"sourceCodeEnd":131,"githubUrl":"https://github.com/antonmedv/fx/blob/4f31cd3a0c5d66f1b4290a2719bab14a5cee8ebe/internal/jsonx/to_value.go#L95-L131","documentation":"ToValue converts an internal JSON Node into a goja (JavaScript) value. It switches on the node's Kind; when the kind is not one of the recognized kinds (Null, Bool, Number, String, Object, Array, Undefined), the node data is corrupted or came from a parser that produced an unknown kind, so it panics with 'unsupported node kind %d'. This is an internal invariant violation, not a user-input error.","triggerScenarios":"Calling ToValue (directly or via KeysComplete) with a Node whose Kind field was never set, was set to a value outside the jsonx kind constants, or came from a third-party constructor that introduced a new kind not yet handled in the switch.","commonSituations":"Developers adding a new Node kind to the AST who forget to add a case in the ToValue switch; building Node values by hand with a zero-valued Kind; a version mismatch where a caller constructs nodes from another package version.","solutions":["Inspect the panic message's kind number and add a matching case to the switch in ToValue (internal/jsonx/to_value.go)","Ensure every Node construction site assigns a valid Kind constant from the jsonx package","Update the library version so the node producer and ToValue switch are from the same code version"],"exampleFix":"// before\ncase Undefined:\n\treturn goja.Undefined()\n}\npanic(fmt.Sprintf(\"unsupported node kind %d\", n.Kind))\n// after\ncase Undefined:\n\treturn goja.Undefined()\ncase MyNewKind:\n\treturn vm.ToValue(n.String())\n}\npanic(fmt.Sprintf(\"unsupported node kind %d\", n.Kind))","handlingStrategy":"type-guard","validationCode":"// before calling ToValue\nif n.Kind < Null || n.Kind > Undefined {\n\treturn fmt.Errorf(\"node has invalid kind %d\", n.Kind)\n}","typeGuard":"func hasSupportedKind(n *jsonx.Node) bool {\n\tswitch n.Kind {\n\tcase jsonx.Null, jsonx.Bool, jsonx.Number, jsonx.String, jsonx.Object, jsonx.Array, jsonx.Undefined:\n\t\treturn true\n\t}\n\treturn false\n}","tryCatchPattern":"// Go has no catch for panics in the same goroutine; wrap if embedding:\nfunc safeToValue(n *jsonx.Node, vm *goja.Runtime) (v goja.Value, err error) {\n\tdefer func() {\n\t\tif r := recover(); r != nil {\n\t\t\terr = fmt.Errorf(\"toValue: %v\", r)\n\t\t}\n\t}()\n\treturn n.ToValue(vm), nil\n}","preventionTips":["Always set Kind from the package's exported constants, never raw ints","Add a switch-exhaustion test covering every Node kind","Keep node-producing and consuming code on the same library version"],"tags":["go","panic","internal-invariant","json"],"backgroundTag":"unsupported-node-kind","analyzedSha":"4f31cd3a0c5d66f1b4290a2719bab14a5cee8ebe","analyzedAt":"2026-09-02T02:17:47.344Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T06:17:21.866Z"}