{"record":{"id":"fedffbebcbb84b4d","repo":"googleapis/mcp-toolbox","slug":"failed-to-stat-file-w","errorCode":null,"errorMessage":"failed to stat file: %w","messagePattern":"failed to stat file: %w","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/internal/migrate/command.go","lineNumber":95,"sourceCode":"\t\t\tcontinue\n\t\t}\n\t\tnewBuf, err := internal.ConvertConfig(ctx, buf)\n\t\tif err != nil {\n\t\t\tlogger.ErrorContext(ctx, err.Error())\n\t\t\terrs = append(errs, err)\n\t\t\tcontinue\n\t\t}\n\t\tif cmp.Equal(buf, newBuf) {\n\t\t\tcontinue\n\t\t}\n\n\t\tif cmd.dryRun {\n\t\t\tlogger.DebugContext(ctx, fmt.Sprintf(\"printing migration to output for file: %s\", filePath))\n\t\t\tfmt.Fprintln(opts.IOStreams.Out, string(newBuf))\n\t\t} else {\n\t\t\tinfo, err := os.Stat(filePath)\n\t\t\tif err != nil {\n\t\t\t\terrMsg := fmt.Errorf(\"failed to stat file: %w\", err)\n\t\t\t\tlogger.ErrorContext(ctx, errMsg.Error())\n\t\t\t\terrs = append(errs, errMsg)\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tbackupFile := filePath + \".bak\"\n\t\t\terr = os.Rename(filePath, backupFile)\n\t\t\tif err != nil {\n\t\t\t\terrMsg := fmt.Errorf(\"failed to rename file: %w\", err)\n\t\t\t\tlogger.ErrorContext(ctx, errMsg.Error())\n\t\t\t\terrs = append(errs, errMsg)\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tlogger.DebugContext(ctx, fmt.Sprintf(\"successfully renamed %s to %s\", filePath, backupFile))\n\n\t\t\t// set the permission to the original file's permission.\n\t\t\terr = os.WriteFile(filePath, newBuf, info.Mode().Perm())\n\t\t\tif err != nil {\n\t\t\t\terrMsg := fmt.Errorf(\"failed to write to file: %w\", err)","sourceCodeStart":77,"sourceCodeEnd":113,"githubUrl":"https://github.com/googleapis/mcp-toolbox/blob/8cc6e09de2ad7b8bffc77751799585a1401a48eb/cmd/internal/migrate/command.go#L77-L113","documentation":"This error is emitted by the `migrate` command in runMigrate when `os.Stat(filePath)` fails on a file it is about to rewrite. The command needs the file's mode bits (to preserve permissions when rewriting) and the file's existence, so a stat failure aborts processing of that one file and the error is appended to the collected error list while other files continue to be processed. Because it wraps the raw os.Stat error, the underlying cause (e.g. ENOENT, EACCES, ENOTDIR) is always included in the wrapped message.","triggerScenarios":"Running the migrate command with a path that does not exist, points to a broken symlink, or lives in a directory the process cannot traverse. Also occurs when the file is deleted between path collection and the stat call, or the path is too long / is a non-directory component (ENOTDIR).","commonSituations":"Typo in a file path or glob expansion produced no/stale paths; running the toolbox from a container or service account whose user lacks execute permission on the parent directory; a broken symlink left behind after an aborted run; an interrupted previous migrate run removed the file but left the .bak.","solutions":["Verify the path exists with `ls -l <filePath>` and fix any typo in the configured path/glob.","Check permissions on the file's parent directory (the process needs +x on it); run as a user with access or chown/chmod the path.","If it is a broken symlink, remove it or recreate it pointing at a real file.","Re-run migrate; the error is per-file and the command continues with other files, so inspect the full error list and fix each offending path.","Check that no concurrent process deleted or moved the file during the run."],"exampleFix":"// before: path comes from a possibly stale config\nfilePath := cfg.OldPath\ninfo, err := os.Stat(filePath) // ENOENT\n// after: resolve and validate the path up front\nif resolved, err := filepath.EvalSymlinks(cfg.OldPath); err == nil {\n    filePath = resolved\n} else {\n    log.Fatalf(\"migrate input %q does not exist: %v\", cfg.OldPath, err)\n}","handlingStrategy":"validation","validationCode":"info, err := os.Stat(filePath)\nif err != nil {\n    return fmt.Errorf(\"skipping %s: not statable (%v); check path and permissions\", filePath, err)\n}\nif info.IsDir() {\n    return fmt.Errorf(\"%s is a directory, expected a file\", filePath)\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Stat every input path in a dry-run pass before running migrate for real.","Avoid hardcoding absolute paths; derive them from the repo root at runtime.","Run migrate as the same user that owns the target files.","Watch for broken symlinks after branch switches or partial cleanups; use filepath.EvalSymlinks."],"tags":["go","filesystem","migrate","file-not-found"],"backgroundTag":"file-not-found","analyzedSha":"8cc6e09de2ad7b8bffc77751799585a1401a48eb","analyzedAt":"2026-09-05T01:10:36.887Z","contentChangedAt":"2026-09-05T01:10:36.887Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}