{"record":{"id":"2ae177227ad3a64d","repo":"hashicorp/nomad","slug":"cannot-serialize-s-2ae177","errorCode":null,"errorMessage":"cannot serialize %s","messagePattern":"cannot serialize (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"jobspec2/parse_map.go","lineNumber":175,"sourceCode":"\tcase t.IsObjectType():\n\t\tresult := map[string]any{}\n\n\t\tfor k := range t.AttributeTypes() {\n\t\t\tav := val.GetAttr(k)\n\t\t\tavv, err := interfaceFromCtyValue(av)\n\t\t\tif err != nil {\n\t\t\t\treturn nil, err\n\t\t\t}\n\n\t\t\tresult[k] = avv\n\t\t}\n\t\treturn result, nil\n\tcase t.IsCapsuleType():\n\t\trawVal := val.EncapsulatedValue()\n\t\treturn rawVal, nil\n\tdefault:\n\t\t// should never happen\n\t\treturn nil, fmt.Errorf(\"cannot serialize %s\", t.FriendlyName())\n\t}\n}\n\nfunc isCollectionOfMaps(t cty.Type) bool {\n\tswitch {\n\tcase t.IsCollectionType():\n\t\tet := t.ElementType()\n\t\treturn et.IsMapType() || et.IsObjectType()\n\tcase t.IsTupleType():\n\t\tets := t.TupleElementTypes()\n\t\tfor _, et := range ets {\n\t\t\tif !et.IsMapType() && !et.IsObjectType() {\n\t\t\t\treturn false\n\t\t\t}\n\t\t}\n\n\t\treturn len(ets) > 0\n\tdefault:","sourceCodeStart":157,"sourceCodeEnd":193,"githubUrl":"https://github.com/hashicorp/nomad/blob/482b49bf1aec006f089bcfc7e632d8f6ac303e5e/jobspec2/parse_map.go#L157-L193","documentation":"interfaceFromCtyValue ends with a default branch for cty types it does not know how to convert to plain Go values (non-primitive, non-collection, non-object/tuple, non-capsule-extractable). The comment says it should never happen; hitting it means the type/conformance contract between decodeInterface and the value was violated or a new cty kind appeared.","triggerScenarios":"decodeInterface invoked with a cty.Type that matches none of the handled switch cases and whose IsCapsuleType branch does not apply, causing 'cannot serialize <FriendlyName>'.","commonSituations":"Bug in the library or an upgraded cty version introducing a type kind jobspec2 does not handle; decoding a value whose declared type does not match its runtime conformance (violated precondition); exotic capsule types from extensions.","solutions":["Report/inspect the type name in the message; confirm the jobspec value's declared type matches the supplied value.","Upgrade (or pin) the hashicorp/hcl2/cty dependency so type kinds and conversion code agree.","Simplify the jobspec construct producing the exotic type (avoid unusual nested/type expressions).","If reproducible, file a bug — this code path is documented as unreachable under correct preconditions."],"exampleFix":"// before\n// val declared as cty.DynamicPseudoType but carries unhandled kind\n\n// after\n// declare explicit concrete types in the jobspec\nvariable \"port\" { type = number }","handlingStrategy":"type-guard","validationCode":"// Pre-check convertibility\ntypeName := t.FriendlyName()\nswitch {\ncase t.IsPrimitiveType(), t.IsCollectionType(), t.IsObjectType(), t.IsTupleType(), t.IsCapsuleType():\n    // handled\ndefault:\n    return fmt.Errorf(\"unsupported cty type for decoding: %s\", typeName)\n}","typeGuard":"func isSupportedCtyType(t cty.Type) bool {\n    return t.IsPrimitiveType() || t.IsCollectionType() ||\n        t.IsObjectType() || t.IsTupleType() || t.IsCapsuleType()\n}","tryCatchPattern":"v, err := interfaceFromCtyValue(val, t)\nif err != nil && strings.HasPrefix(err.Error(), \"cannot serialize \") {\n    // capture type name, check dependency versions, report bug\n}","preventionTips":["Keep hashicorp/hcl2 and cty versions aligned with the library's expectations.","Declare explicit concrete types in jobspec variables.","Treat this error as a bug signal: report with the type name from the message."],"tags":["hcl","cty","serialization","jobspec"],"backgroundTag":"unsupported-type","analyzedSha":"482b49bf1aec006f089bcfc7e632d8f6ac303e5e","analyzedAt":"2026-09-04T07:54:14.808Z","contentChangedAt":"2026-09-04T07:54:14.808Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}