hashicorp/terraform · warning

No file or directory at %s

Error message

No file or directory at %s

What it means

Returned by FmtCommand.fmt (fmt.go:128) when os.Stat fails for a user-supplied target path. fmt iterates over the provided paths and stats each; if stat fails the path does not exist (or is inaccessible), and fmt reports it without proceeding to format that path. This is a precondition check before the directory/file branching.

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 c9def3e214)

Solutions

  1. Verify the path exists: `ls -la <path>` and fix typos or use an absolute path.
  2. Re-run fmt from the directory containing the target, or use a relative path from the correct cwd.
  3. If a parent directory lacks execute permission, fix it: `chmod +x <parent>`.
  4. Ensure the filesystem is mounted if the path is on a removable/network volume.

Example fix

# before
terraform fmt ./modoules/vpc  # typo
# No file or directory at ./modoules/vpc

# after
terraform fmt ./modules/vpc
Defensive patterns

Strategy: validation

Validate before calling

// Stat each path up front and report missing ones together
for _, p := range paths {
    if _, err := os.Stat(p); err != nil {
        return fmt.Errorf("target does not exist: %s", p)
    }
}

Prevention

When it happens

Trigger: os.Stat(path) returns an error: the path does not exist (typo, wrong relative path), the path exists but a parent component lacks execute permission (search denied), or the path is on an unmounted filesystem. Most commonly the path simply does not exist.

Common situations: Typo in the target path; running fmt from the wrong working directory; path deleted between glob expansion and execution; absolute path pointing at a different machine's layout copied from docs; permission denied on a path component.

Related errors


AI-assisted analysis of hashicorp/terraform@c9def3e214 (2026-08-07). Data as JSON: /api/errors/34345b102b69418b. Report an issue: GitHub.