hashicorp/nomad · error

Failed to list directory %s

Error message

Failed to list directory %s

What it means

processDir wraps os.ReadDir; if the directory cannot be read (missing path, not a directory, permission denied), the underlying error is discarded and a generic 'Failed to list directory <path>' is appended.

Source

Thrown at command/fmt.go:203

					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() {
			if f.recursive {
				f.processDir(subpath)
			}

			continue
		}

		info, err := entry.Info()
		if err != nil {
			f.appendError(err)

View on GitHub (pinned to 482b49bf1a)

Solutions

  1. Verify the directory path exists with ls before running nomad fmt
  2. Check filesystem permissions on the directory (ls -ld)
  3. Confirm the argument is a directory, not a file
  4. Run with a user that has read access to the path

Example fix

// before
nomad fmt ./jobss   # typo
// after
nomad fmt ./jobs
Defensive patterns

Strategy: validation

Validate before calling

if info, err := os.Stat(path); err != nil || !info.IsDir() {
    return fmt.Errorf("%s is not a readable directory", path)
}

Prevention

When it happens

Trigger: `nomad fmt ./dir` where ./dir does not exist, is a file, or the process lacks read permission on it.

Common situations: Typo in the directory path passed to nomad fmt; running as a user without permissions on a shared mount; passing a single file path where fmt expects to recurse a directory.

Related errors


AI-assisted analysis of hashicorp/nomad@482b49bf1a (2026-09-04). Data as JSON: /api/errors/67c2ea33fa213ca3. Report an issue: GitHub.