hashicorp/terraform · warning
No file or directory at
Error message
No file or directory at %s
What it means
Thrown by FmtCommand.fmt when os.Stat fails for a path argument supplied to `terraform fmt`. Stat is the existence/type gate before formatting; any error (not just NotExist) triggers this. The path is the normalized form (after normalizePath).
Solutions
- Verify the path exists and is spelled correctly: `ls -l <path>`.
- Use an absolute path or ensure relative paths resolve from the shell's cwd.
- Expand tildes explicitly ($HOME) or rely on the shell, not Terraform, to expand them.
- Check parent directory execute permissions if traversal is the issue.
Example fix
// before // terraform fmt ./infrastructure/main.tf # typo: dir is 'infra' // after // terraform fmt ./infra/main.tf
Defensive patterns
Strategy: validation
Validate before calling
func pathExists(p string) error {
if _, err := os.Stat(p); err != nil {
return fmt.Errorf("no file or directory at %s: %w", p, err)
}
return nil
} Prevention
- Use absolute paths or verify relative paths from the shell cwd.
- Expand tildes via the shell ($HOME), not Terraform.
- Double-check spelling and case of paths.
When it happens
Trigger: Passing a path that does not exist, is a broken symlink, lives behind a permission wall (EACCES), or whose parent directory cannot be traversed. Also a typo in the path.
Common situations: Typo in filename; running fmt from the wrong working directory; path uses a tilde that was not expanded; broken symlink; permission to traverse a parent dir missing; case-sensitivity mismatch on case-insensitive filesystems.
Related errors
- Failed to read file
- Option -write cannot be used when reading from stdin
- Error getting pwd
- Failed to get absolute path of the configuration directory
- No '=' value in arg
AI-assisted analysis of hashicorp/terraform@d32a084675 (2026-08-11).
Data as JSON: /api/errors/34345b102b69418b.
Report an issue: GitHub.
Appendix: source
Thrown at internal/command/fmt.go:132
func (c *FmtCommand) fmt(paths []string, stdin io.Reader, stdout io.Writer) tfdiags.Diagnostics {
var diags tfdiags.Diagnostics
if len(paths) == 0 { // Assuming stdin, then.
if c.write {
diags = diags.Append(fmt.Errorf("Option -write cannot be used when reading from stdin"))
return diags
}
fileDiags := c.processFile("<stdin>", stdin, stdout, true)
diags = diags.Append(fileDiags)
return diags
}
for _, path := range paths {
path = c.normalizePath(path)
info, err := os.Stat(path)
if err != nil {
diags = diags.Append(fmt.Errorf("No file or directory at %s", path))
return diags
}
if info.IsDir() {
dirDiags := c.processDir(path, stdout)
diags = diags.Append(dirDiags)
} else {
fmtd := false
for _, ext := range fmtSupportedExts {
if strings.HasSuffix(path, ext) {
f, err := os.Open(path)
if err != nil {
// Open does not produce error messages that are end-user-appropriate,
// so we'll need to simplify here.
diags = diags.Append(fmt.Errorf("Failed to read file %s", path))
continue
}
fileDiags := c.processFile(c.normalizePath(path), f, stdout, false)View on GitHub (pinned to d32a084675)