{"record":{"id":"21c5ccb93cb78558","repo":"hashicorp/nomad","slug":"label-encoding-failed-v","errorCode":null,"errorMessage":"Label encoding failed: %v","messagePattern":"Label encoding failed: (.+?)","errorType":"validation","errorClass":"hcl.Diagnostic","httpStatus":null,"severity":"error","filePath":"helper/pluginutils/hclutils/util.go","lineNumber":47,"sourceCode":"\tevalCtx := &hcl.EvalContext{\n\t\tVariables: vars,\n\t\tFunctions: GetStdlibFuncs(),\n\t}\n\n\t// Encode to json\n\tvar buf bytes.Buffer\n\tenc := codec.NewEncoder(&buf, structs.JsonHandle)\n\terr := enc.Encode(val)\n\tif err != nil {\n\t\t// Convert to a hcl diagnostics message\n\t\terrorMessage := fmt.Sprintf(\"Label encoding failed: %v\", err)\n\t\treturn cty.NilVal,\n\t\t\thcl.Diagnostics([]*hcl.Diagnostic{{\n\t\t\t\tSeverity: hcl.DiagError,\n\t\t\t\tSummary:  \"Failed to encode label value\",\n\t\t\t\tDetail:   errorMessage,\n\t\t\t}}),\n\t\t\t[]error{errors.New(errorMessage)}\n\t}\n\n\t// Parse the json as hcl2\n\thclFile, diag := hjson.Parse(buf.Bytes(), \"\")\n\tif diag.HasErrors() {\n\t\treturn cty.NilVal, diag, formattedDiagnosticErrors(diag)\n\t}\n\n\tvalue, decDiag := hcldec.Decode(hclFile.Body, spec, evalCtx)\n\tdiag = diag.Extend(decDiag)\n\tif diag.HasErrors() {\n\t\treturn cty.NilVal, diag, formattedDiagnosticErrors(diag)\n\t}\n\n\treturn value, diag, nil\n}\n\n// CtyValueToMapInterface converts a decoded cty value into a Go","sourceCodeStart":29,"sourceCodeEnd":65,"githubUrl":"https://github.com/hashicorp/nomad/blob/482b49bf1aec006f089bcfc7e632d8f6ac303e5e/helper/pluginutils/hclutils/util.go#L29-L65","documentation":"ParseHclInterface decodes plugin configuration (an hcl2 body / cty value) into a map. When a labeled block or attribute's value cannot be HCL-encoded, it builds the message \"Label encoding failed: %v\" with the underlying error and returns it as an hcl.Diagnostic plus an error, e.g. for a label value of the wrong type.","triggerScenarios":"Calling hclutils.ParseHclInterface (directly or via validatePluginConfig / driver config parsing like runDriver) with a config where a label value cannot be encoded to the expected type — e.g. a non-string value where a string label is required, or malformed nested structures.","commonSituations":"Task driver plugin config blocks (docker, qemu, etc.) in job files with mistyped values (numbers/booleans where strings are expected); plugin configs loaded via RPC validation; tests feeding cty values of unexpected shape.","solutions":["Read the Detail of the returned hcl.Diagnostics — it wraps the underlying encoding error naming the offending label.","Fix the job/plugin config so the labeled value matches the expected schema (usually a string label).","Validate the config with `nomad job validate` or validatePluginConfig before submitting to catch this client-side."],"exampleFix":"// before (job config)\nconfig {\n  image = 42\n}\n// after\nconfig {\n  image = \"redis:7\"\n}","handlingStrategy":"validation","validationCode":"// ensure labeled values are strings before parsing\nfor k, v := range rawConfig {\n    if isLabelKey(k) {\n        if _, ok := v.(string); !ok {\n            return fmt.Errorf(\"label %q must be a string, got %T\", k, v)\n        }\n    }\n}\n_, diags, errs := hclutils.ParseHclInterface(raw, ctyToHclSchema(), nil)","typeGuard":"func isStringValue(v interface{}) bool { _, ok := v.(string); return ok }","tryCatchPattern":"m, diags, errs := hclutils.ParseHclInterface(in, ctyType, ctx)\nif len(errs) > 0 {\n    for _, e := range errs {\n        if strings.HasPrefix(e.Error(), \"Label encoding failed\") {\n            return fmt.Errorf(\"check job config label values: %w\", e)\n        }\n    }\n    return diags\n}","preventionTips":["Run `nomad job validate` before submitting jobs with driver configs.","Quote string values in HCL config blocks to avoid type coercion issues.","Keep plugin config schemas in sync with job files across Nomad upgrades."],"tags":["hcl","config-validation","plugin"],"backgroundTag":"hcl-decode-failed","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"}