{"record":{"id":"0edd296f01acd88c","repo":"hashicorp/nomad","slug":"only-nomad-and-hcl-files-can-be-processed-using","errorCode":null,"errorMessage":"Only .nomad and .hcl files can be processed using nomad fmt","messagePattern":"Only \\.nomad and \\.hcl files can be processed using nomad fmt","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"command/fmt.go","lineNumber":193,"sourceCode":"\t\t\tf.appendError(fmt.Errorf(\"No file or directory at %s\", path))\n\t\t\tcontinue\n\t\t}\n\n\t\tif info.IsDir() {\n\t\t\tf.processDir(path)\n\t\t} else {\n\t\t\tif isNomadFile(info) {\n\t\t\t\tfp, err := os.Open(path)\n\t\t\t\tif err != nil {\n\t\t\t\t\tf.appendError(fmt.Errorf(\"Failed to open file %s: %w\", path, err))\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\n\t\t\t\tf.processFile(path, fp)\n\n\t\t\t\tfp.Close()\n\t\t\t} else {\n\t\t\t\tf.appendError(fmt.Errorf(\"Only .nomad and .hcl files can be processed using nomad fmt\"))\n\t\t\t\tcontinue\n\t\t\t}\n\t\t}\n\t}\n}\n\nfunc (f *FormatCommand) processDir(path string) {\n\tentries, err := os.ReadDir(path)\n\tif err != nil {\n\t\tf.appendError(fmt.Errorf(\"Failed to list directory %s\", path))\n\t\treturn\n\t}\n\n\tfor _, entry := range entries {\n\t\tname := entry.Name()\n\t\tsubpath := filepath.Join(path, name)\n\n\t\tif entry.IsDir() {","sourceCodeStart":175,"sourceCodeEnd":211,"githubUrl":"https://github.com/hashicorp/nomad/blob/482b49bf1aec006f089bcfc7e632d8f6ac303e5e/command/fmt.go#L175-L211","documentation":"nomad fmt only accepts files with .nomad or .hcl extensions; this error is appended by the fmt command when it encounters any other file extension and skips it. The command exists solely to format Nomad job/HCL files, so other files are intentionally rejected.","triggerScenarios":"Running `nomad fmt` on a directory (or passing a file) that contains files without .nomad/.hcl extensions, e.g. `nomad fmt ./config` picking up .json, .tf, .txt files.","commonSituations":"Formatting a directory that mixes Nomad jobs with scripts or README files; a job file saved without an extension; typos like job.nomad.bak or .yaml files.","solutions":["Rename the target files to use .nomad or .hcl extensions","Pass the specific .nomad/.hcl files you want formatted instead of a directory","Move non-HCL files out of the target directory","Inspect the appended errors in the command output to see which files were skipped"],"exampleFix":"// before\nmv myjob.yaml jobs/\n// after\nmv myjob.yaml myjob.nomad","handlingStrategy":"validation","validationCode":"files, _ := os.ReadDir(dir)\nfor _, f := range files {\n    if ext := filepath.Ext(f.Name()); ext != \".nomad\" && ext != \".hcl\" {\n        fmt.Printf(\"skipping non-HCL file: %s\\n\", f.Name())\n    }\n}","typeGuard":"func isFormattable(name string) bool {\n    return filepath.Ext(name) == \".nomad\" || filepath.Ext(name) == \".hcl\"\n}","tryCatchPattern":null,"preventionTips":["Keep Nomad job files in dedicated directories","Always use .nomad or .hcl extensions for job/HCL files","Filter directories before invoking nomad fmt"],"tags":["cli","fmt","file-extension","validation"],"backgroundTag":"unsupported-file-extension","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"}