hashicorp/nomad · warning
Only .nomad and .hcl files can be processed using nomad fmt
Error message
Only .nomad and .hcl files can be processed using nomad fmt
What it means
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.
Source
Thrown at command/fmt.go:193
f.appendError(fmt.Errorf("No file or directory at %s", path))
continue
}
if info.IsDir() {
f.processDir(path)
} else {
if isNomadFile(info) {
fp, err := os.Open(path)
if err != nil {
f.appendError(fmt.Errorf("Failed to open file %s: %w", path, err))
continue
}
f.processFile(path, fp)
fp.Close()
} else {
f.appendError(fmt.Errorf("Only .nomad and .hcl files can be processed using nomad fmt"))
continue
}
}
}
}
func (f *FormatCommand) processDir(path string) {
entries, err := os.ReadDir(path)
if err != nil {
f.appendError(fmt.Errorf("Failed to list directory %s", path))
return
}
for _, entry := range entries {
name := entry.Name()
subpath := filepath.Join(path, name)
if entry.IsDir() {View on GitHub (pinned to 482b49bf1a)
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
Example fix
// before mv myjob.yaml jobs/ // after mv myjob.yaml myjob.nomad
Defensive patterns
Strategy: validation
Validate before calling
files, _ := os.ReadDir(dir)
for _, f := range files {
if ext := filepath.Ext(f.Name()); ext != ".nomad" && ext != ".hcl" {
fmt.Printf("skipping non-HCL file: %s\n", f.Name())
}
} Type guard
func isFormattable(name string) bool {
return filepath.Ext(name) == ".nomad" || filepath.Ext(name) == ".hcl"
} Prevention
- Keep Nomad job files in dedicated directories
- Always use .nomad or .hcl extensions for job/HCL files
- Filter directories before invoking nomad fmt
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- The '-template' flag is only valid when using 'go-template'
- A template must be supplied using '-template' when using go-
- Invalid value for "-out"; valid values are [go-template, hcl
- The '-template' flag is only valid when using 'go-template'
- A template must be supplied using '-template' when using go-
AI-assisted analysis of hashicorp/nomad@482b49bf1a (2026-09-04).
Data as JSON: /api/errors/0edd296f01acd88c.
Report an issue: GitHub.