{"record":{"id":"34345b102b69418b","repo":"hashicorp/terraform","slug":"no-file-or-directory-at-s","errorCode":null,"errorMessage":"No file or directory at %s","messagePattern":"No file or directory at (.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"internal/command/fmt.go","lineNumber":132,"sourceCode":"\nfunc (c *FmtCommand) fmt(paths []string, stdin io.Reader, stdout io.Writer) tfdiags.Diagnostics {\n\tvar diags tfdiags.Diagnostics\n\n\tif len(paths) == 0 { // Assuming stdin, then.\n\t\tif c.write {\n\t\t\tdiags = diags.Append(fmt.Errorf(\"Option -write cannot be used when reading from stdin\"))\n\t\t\treturn diags\n\t\t}\n\t\tfileDiags := c.processFile(\"<stdin>\", stdin, stdout, true)\n\t\tdiags = diags.Append(fileDiags)\n\t\treturn diags\n\t}\n\n\tfor _, path := range paths {\n\t\tpath = c.normalizePath(path)\n\t\tinfo, err := os.Stat(path)\n\t\tif err != nil {\n\t\t\tdiags = diags.Append(fmt.Errorf(\"No file or directory at %s\", path))\n\t\t\treturn diags\n\t\t}\n\t\tif info.IsDir() {\n\t\t\tdirDiags := c.processDir(path, stdout)\n\t\t\tdiags = diags.Append(dirDiags)\n\t\t} else {\n\t\t\tfmtd := false\n\t\t\tfor _, ext := range fmtSupportedExts {\n\t\t\t\tif strings.HasSuffix(path, ext) {\n\t\t\t\t\tf, err := os.Open(path)\n\t\t\t\t\tif err != nil {\n\t\t\t\t\t\t// Open does not produce error messages that are end-user-appropriate,\n\t\t\t\t\t\t// so we'll need to simplify here.\n\t\t\t\t\t\tdiags = diags.Append(fmt.Errorf(\"Failed to read file %s\", path))\n\t\t\t\t\t\tcontinue\n\t\t\t\t\t}\n\n\t\t\t\t\tfileDiags := c.processFile(c.normalizePath(path), f, stdout, false)","sourceCodeStart":114,"sourceCodeEnd":150,"githubUrl":"https://github.com/hashicorp/terraform/blob/d32a084675427f5ac3f7d2868578ef8b2c1dc525/internal/command/fmt.go#L114-L150","documentation":"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).","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\n//   terraform fmt ./infrastructure/main.tf   # typo: dir is 'infra'\n// after\n//   terraform fmt ./infra/main.tf","handlingStrategy":"validation","validationCode":"func pathExists(p string) error {\n    if _, err := os.Stat(p); err != nil {\n        return fmt.Errorf(\"no file or directory at %s: %w\", p, err)\n    }\n    return nil\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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."],"tags":["fmt","cli","filesystem","user-error","path"],"backgroundTag":null,"analyzedSha":"d32a084675427f5ac3f7d2868578ef8b2c1dc525","analyzedAt":"2026-08-11T18:43:52.779Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}