{"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/c9def3e214014c1188faabfc4a5bde5095139765/internal/command/fmt.go#L114-L150","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Verify the path exists: `ls -la <path>` and fix typos or use an absolute path.","Re-run fmt from the directory containing the target, or use a relative path from the correct cwd.","If a parent directory lacks execute permission, fix it: `chmod +x <parent>`.","Ensure the filesystem is mounted if the path is on a removable/network volume."],"exampleFix":"# before\nterraform fmt ./modoules/vpc  # typo\n# No file or directory at ./modoules/vpc\n\n# after\nterraform fmt ./modules/vpc","handlingStrategy":"validation","validationCode":"// Stat each path up front and report missing ones together\nfor _, p := range paths {\n    if _, err := os.Stat(p); err != nil {\n        return fmt.Errorf(\"target does not exist: %s\", p)\n    }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Validate paths with os.Stat before invoking fmt.","Use absolute paths or run from the directory containing the target.","Double-check glob expansions before passing them to fmt.","Ensure network/removable volumes are mounted."],"tags":["cli","fmt","filesystem","user-input","path"],"analyzedSha":"c9def3e214014c1188faabfc4a5bde5095139765","analyzedAt":"2026-08-07T15:39:49.278Z","schemaVersion":2},"datasetVersion":"2026-08-07T21:17:07.882Z"}