{"record":{"id":"7a5169e095c2e6e2","repo":"ory/kratos","slug":"unknown-node-type-t","errorCode":null,"errorMessage":"unknown node type: %T","messagePattern":"unknown node type: %T","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"ui/node/node.go","lineNumber":562,"sourceCode":"\t\t\tt = Text\n\t\t\tattr.NodeType = Text\n\t\tcase *InputAttributes:\n\t\t\tt = Input\n\t\t\tattr.NodeType = Input\n\t\tcase *AnchorAttributes:\n\t\t\tt = Anchor\n\t\t\tattr.NodeType = Anchor\n\t\tcase *ImageAttributes:\n\t\t\tt = Image\n\t\t\tattr.NodeType = Image\n\t\tcase *ScriptAttributes:\n\t\t\tt = Script\n\t\t\tattr.NodeType = Script\n\t\tcase *DivisionAttributes:\n\t\t\tt = Division\n\t\t\tattr.NodeType = Division\n\t\tdefault:\n\t\t\treturn nil, errors.WithStack(fmt.Errorf(\"unknown node type: %T\", n.Attributes))\n\t\t}\n\t}\n\n\tif n.Type == \"\" {\n\t\tn.Type = t\n\t} else if n.Type != t {\n\t\treturn nil, errors.WithStack(fmt.Errorf(\"node type and node attributes mismatch: %T != %s\", n.Attributes, n.Type))\n\t}\n\n\tif n.Meta == nil {\n\t\tn.Meta = new(Meta)\n\t}\n\n\treturn json.Marshal((*jsonRawNode)(n))\n}\n","sourceCodeStart":544,"sourceCodeEnd":578,"githubUrl":"https://github.com/ory/kratos/blob/b86338da04a040247a07f46100a86dcfb3875909/ui/node/node.go#L544-L578","documentation":"During node JSON serialization (MarshalJSON in ui/node/node.go), the library inspects the concrete type of n.Attributes to derive the node type discriminator. If Attributes holds a struct that is not one of the known attribute types, serialization cannot proceed because the emitted \"type\" field would be meaningless.","triggerScenarios":"Constructing a Node with an Attributes value of an unsupported/custom *XxxAttributes type (not TextAttributes, InputAttributes, ScriptAttributes, DivisionAttributes, etc.) and then marshaling the node or a flow containing it to JSON.","commonSituations":"Extending the UI node system with custom attribute structs without forking the library; a refactor renamed/moved an attributes type so it no longer matches the switch; test code populating Attributes with a wrong struct.","solutions":["Use only the attribute structs the library defines (InputAttributes, TextAttributes, ImageAttributes, ScriptAttributes, AnchorAttributes, DivisionAttributes, ...).","Check the %T value in the message to identify the unexpected attributes type you set.","Remove custom attribute structs or add them to the MarshalJSON switch in a fork/patch.","Ensure refactors did not accidentally assign an internal wrapper struct to Attributes."],"exampleFix":"// before\nnode.Attributes = &MyCustomAttributes{Foo: \"bar\"}\n// after\nnode.Attributes = &TextAttributes{NodeType: Text, Text: ctx(TextContext{ID: \"my-id\"})}","handlingStrategy":"type-guard","validationCode":"switch n.Attributes.(type) {\ncase *ui.InputAttributes, *ui.TextAttributes, *ui.ImageAttributes, *ui.ScriptAttributes, *ui.AnchorAttributes, *ui.DivisionAttributes:\n    // safe to marshal\ndefault:\n    // unsupported attributes type\n}","typeGuard":"func hasMarshalableAttributes(n *ui.Node) bool {\n    switch n.Attributes.(type) {\n    case *ui.InputAttributes, *ui.TextAttributes, *ui.ImageAttributes,\n         *ui.ScriptAttributes, *ui.AnchorAttributes, *ui.DivisionAttributes:\n        return true\n    default:\n        return false\n    }\n}","tryCatchPattern":"data, err := json.Marshal(node)\nif err != nil {\n    var stackErr interface{ StackTrace() errors.StackTrace }\n    if errors.As(err, &stackErr) || strings.Contains(err.Error(), \"unknown node type\") {\n        log.Error(\"node has unsupported Attributes type\", \"err\", err)\n    }\n}","preventionTips":["Only assign the SDK's exported attribute structs to Node.Attributes.","Never store custom/internal structs in Attributes; convert to a supported type first.","After refactors, run a round-trip (marshal→unmarshal) test over all node kinds."],"tags":["json","marshal","ui-nodes","type-safety"],"backgroundTag":"json-marshal-failed","analyzedSha":"b86338da04a040247a07f46100a86dcfb3875909","analyzedAt":"2026-09-07T15:58:15.934Z","contentChangedAt":"2026-09-07T15:58:15.934Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}