{"record":{"id":"4ce332709a5da44c","repo":"hashicorp/nomad","slug":"unsupported-primitive-type","errorCode":null,"errorMessage":"unsupported primitive type","messagePattern":"unsupported primitive type","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"helper/pluginutils/hclutils/util.go","lineNumber":125,"sourceCode":"\t}\n\n\tswitch {\n\tcase t.IsPrimitiveType():\n\t\tswitch t {\n\t\tcase cty.String:\n\t\t\treturn val.AsString(), nil\n\t\tcase cty.Number:\n\t\t\tif val.RawEquals(cty.PositiveInfinity) {\n\t\t\t\treturn math.Inf(1), nil\n\t\t\t}\n\t\t\tif val.RawEquals(cty.NegativeInfinity) {\n\t\t\t\treturn math.Inf(-1), nil\n\t\t\t}\n\t\t\treturn smallestNumber(val.AsBigFloat()), nil\n\t\tcase cty.Bool:\n\t\t\treturn val.True(), nil\n\t\tdefault:\n\t\t\tpanic(\"unsupported primitive type\")\n\t\t}\n\n\tcase t.IsListType(), t.IsSetType(), t.IsTupleType():\n\t\tresult := []interface{}{}\n\n\t\tit := val.ElementIterator()\n\t\tfor it.Next() {\n\t\t\t_, ev := it.Element()\n\t\t\tevi, err := ctyValueToInterface(ev)\n\t\t\tif err != nil {\n\t\t\t\treturn nil, err\n\t\t\t}\n\t\t\tresult = append(result, evi)\n\t\t}\n\t\treturn result, nil\n\n\tcase t.IsMapType():\n\t\tresult := map[string]interface{}{}","sourceCodeStart":107,"sourceCodeEnd":143,"githubUrl":"https://github.com/hashicorp/nomad/blob/482b49bf1aec006f089bcfc7e632d8f6ac303e5e/helper/pluginutils/hclutils/util.go#L107-L143","documentation":"hclutils.ctyValueToInterface converts cty values (HCL expression results) into Go interface values. It handles cty.Number and cty.Bool primitives; any other primitive cty type (e.g. cty.String reaching this branch unexpectedly, or a new primitive kind) hits the default and panics, since the type system should prevent it.","triggerScenarios":"Evaluating an HCL expression whose cty primitive type is not Number or Bool in the conversion path — e.g. a string-typed cty value routed through CtyValueToMapInterface, or a newly added cty primitive type not handled by the switch.","commonSituations":"Job specs using HCL features producing primitive types the converter doesn't expect; plugin/task config schemas drifting from what ctyValueToInterface handles; custom cty types in forked code paths.","solutions":["Add a case for the missing primitive type (e.g. cty.String -> val.AsString()) in ctyValueToInterface","Verify the value's type before conversion with t == cty.String etc., and route strings through the correct branch","Check the HCL job/config expression for constructs producing unexpected primitive types","Report a bug to Nomad with the job spec that triggered it"],"exampleFix":"// before\ndefault:\n    panic(\"unsupported primitive type\")\n// after\ncase t == cty.String:\n    return val.AsString(), nil\ndefault:\n    return nil, fmt.Errorf(\"unsupported primitive type: %s\", t.FriendlyName())","handlingStrategy":"type-guard","validationCode":"func convertiblePrimitive(t cty.Type) bool {\n    return t == cty.Number || t == cty.Bool || t == cty.String\n}\nif !convertiblePrimitive(val.Type()) { return nil }\n","typeGuard":"func ctyToIfaceSafe(val cty.Value) (out interface{}, err error) {\n    defer func() {\n        if r := recover(); r != nil {\n            err = fmt.Errorf(\"unsupported cty type %s\", val.Type().FriendlyName())\n        }\n    }()\n    return hclutils.CtyValueToMapInterface(val), nil\n}\n","tryCatchPattern":"defer func() {\n    if r := recover(); r != nil {\n        err = fmt.Errorf(\"cty conversion failed: %v\", r)\n    }\n}()","preventionTips":["Check the cty.Type before conversion and handle strings explicitly","Keep hclutils conversion in sync with cty versions in use","Test job specs with all primitive config types"],"tags":["hcl","cty","panic","type-conversion"],"backgroundTag":"cty-primitive-type-unsupported","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"}