{"record":{"id":"c74ce1756124c7a1","repo":"hashicorp/nomad","slug":"s-must-be-integer-got-t-2-v","errorCode":null,"errorMessage":"%s must be integer; got (%T) %[2]v","messagePattern":"(.+?) must be integer; got \\(%T\\) %\\[2\\]v","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"command/var_put.go","lineNumber":516,"sourceCode":"\t// Check for invalid keys\n\tvalid := []string{\n\t\t\"namespace\",\n\t\t\"path\",\n\t\t\"create_index\",\n\t\t\"modify_index\",\n\t\t\"create_time\",\n\t\t\"modify_time\",\n\t\t\"items\",\n\t}\n\tif err := helper.CheckHCLKeys(list, valid); err != nil {\n\t\treturn err\n\t}\n\n\tfor _, index := range []string{\"create_index\", \"modify_index\"} {\n\t\tif value, ok := m[index]; ok {\n\t\t\tvInt, ok := value.(int)\n\t\t\tif !ok {\n\t\t\t\treturn fmt.Errorf(\"%s must be integer; got (%T) %[2]v\", index, value)\n\t\t\t}\n\t\t\tidx := uint64(vInt)\n\t\t\tn := strings.ReplaceAll(\n\t\t\t\tcases.Title(language.English).String(\n\t\t\t\t\tstrings.ReplaceAll(index, \"_\", \" \"),\n\t\t\t\t), \" \", \"\")\n\t\t\tm[n] = idx\n\t\t\tdelete(m, index)\n\t\t}\n\t}\n\n\tfor _, index := range []string{\"create_time\", \"modify_time\"} {\n\t\tif value, ok := m[index]; ok {\n\t\t\tvInt, ok := value.(int)\n\t\t\tif !ok {\n\t\t\t\treturn fmt.Errorf(\"%s must be a int64; got a (%T) %[2]v\", index, value)\n\t\t\t}\n\t\t\tn := strings.ReplaceAll(","sourceCodeStart":498,"sourceCodeEnd":534,"githubUrl":"https://github.com/hashicorp/nomad/blob/482b49bf1aec006f089bcfc7e632d8f6ac303e5e/command/var_put.go#L498-L534","documentation":"parseVariableSpecImpl maps raw HCL-decoded values onto api.Variable fields. `create_index` and `modify_index` must decode as Go ints; if the HCL file supplies them as another type (string, float, etc.) the function returns `%s must be integer; got (%T) %v`, naming the offending key and its actual Go type/value.","triggerScenarios":"An .hcl spec containing `create_index = \"12\"` or a non-integer literal (e.g. `12.0`) for `create_index`/`modify_index`, typically because the value was copy-pasted from `nomad var read` output in JSON form where indexes appear as quoted or large numbers.","commonSituations":"Round-tripping a variable read from the API into an HCL spec without removing read-only fields (CreateIndex/ModifyIndex are server-managed and should generally be omitted from specs).","solutions":["Remove `create_index`/`modify_index` from the spec entirely — the server manages these fields.","If they must be present, write them as bare integers: `create_index = 42`, no quotes or decimals.","Regenerate the spec from `nomad var init` instead of editing API output."],"exampleFix":"// before\ncreate_index = \"42\"\n// after\ncreate_index = 42","handlingStrategy":"validation","validationCode":"# strip server-managed fields from the spec before submitting\ngrep -E '^(create_index|modify_index)\\s*=' spec.hcl && { echo 'remove create_index/modify_index from spec' >&2; exit 1; } || true","typeGuard":null,"tryCatchPattern":"if err := run(); err != nil {\n    var terr *fmt.Errorf // message contains 'must be integer'\n    if strings.Contains(err.Error(), \"must be integer\") {\n        log.Fatalf(\"spec index field wrong type: %v\", err)\n    }\n    log.Fatal(err)\n}","preventionTips":["Never copy server-managed fields (create_index, modify_index) from API output into specs.","If present, write them as bare integers, never quoted strings or floats.","Build specs from the `nomad var init` template, which omits these fields."],"tags":["hcl","nomad","type-mismatch","validation"],"backgroundTag":"type-mismatch","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"}