{"record":{"id":"67d1eadbc0e5685c","repo":"wavetermdev/waveterm","slug":"failed-to-stat-file-w-67d1ea","errorCode":null,"errorMessage":"failed to stat file: %w","messagePattern":"failed to stat file: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/waveappstore/waveappstore.go","lineNumber":306,"sourceCode":"\nfunc ReadAppFile(appId string, fileName string) (*FileData, error) {\n\tif err := ValidateAppId(appId); err != nil {\n\t\treturn nil, fmt.Errorf(\"invalid appId: %w\", err)\n\t}\n\n\tappDir, err := GetAppDir(appId)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\tfilePath, err := validateAndResolveFilePath(appDir, fileName)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\tfileInfo, err := os.Stat(filePath)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to stat file: %w\", err)\n\t}\n\n\tcontents, err := os.ReadFile(filePath)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to read file: %w\", err)\n\t}\n\n\treturn &FileData{\n\t\tContents: contents,\n\t\tModTs:    fileInfo.ModTime().UnixMilli(),\n\t}, nil\n}\n\nfunc DeleteAppFile(appId string, fileName string) error {\n\tif err := ValidateAppId(appId); err != nil {\n\t\treturn fmt.Errorf(\"invalid appId: %w\", err)\n\t}\n","sourceCodeStart":288,"sourceCodeEnd":324,"githubUrl":"https://github.com/wavetermdev/waveterm/blob/a4447c1563b2df285ab89e76c82f91e1a1a49c1e/pkg/waveappstore/waveappstore.go#L288-L324","documentation":"ReadAppFile calls os.Stat on the resolved file path to get the modification time before reading. This error wraps a failed os.Stat (waveappstore.go:304-307). The dominant case is the file not existing (fs.ErrNotExist); it can also be a permission problem on a parent directory.","triggerScenarios":"Calling ReadAppFile (or ReadAppFileCommand, generateBuilderAppData) for a fileName that does not exist inside the app directory, an app directory that does not exist yet, or a path whose parent dirs are unreadable.","commonSituations":"Reading a file from an app that was never created or was deleted; a typo in the file name; checking a file before WriteAppFile ever ran; reading across namespaces (draft vs local) where the file only exists in the other one.","solutions":["Check the wrapped error with errors.Is(err, fs.ErrNotExist) and treat it as 'file missing' rather than a hard failure.","Verify the app exists first (waveappstore.ListAllAppFiles or os.Stat on waveappstore.GetAppDir(appId)).","Confirm the namespace: 'draft/myapp' and 'local/myapp' are separate directories; the file may only exist in one.","Fix the fileName spelling; path names are case-sensitive on Linux."],"exampleFix":"// before\ndata, err := waveappstore.ReadAppFile(appId, fileName)\nif err != nil { return err } // treats missing file as fatal\n\n// after\ndata, err := waveappstore.ReadAppFile(appId, fileName)\nif err != nil {\n    if errors.Is(err, fs.ErrNotExist) {\n        return nil, nil // file not written yet — handle as empty\n    }\n    return err\n}","handlingStrategy":"try-catch","validationCode":"func fileExists(appId, fileName string) bool {\n    dir, err := waveappstore.GetAppDir(appId)\n    if err != nil { return false }\n    _, err = os.Stat(filepath.Join(dir, filepath.Clean(fileName)))\n    return err == nil\n}","typeGuard":null,"tryCatchPattern":"data, err := waveappstore.ReadAppFile(appId, fileName)\nif err != nil {\n    if errors.Is(err, fs.ErrNotExist) {\n        return nil, nil // treat as absent\n    }\n    return nil, err\n}","preventionTips":["Check the app exists (ListAllAppFiles) before reading individual files.","Be explicit about namespace: draft files are separate from local files.","Verify file name spelling and case.","Treat fs.ErrNotExist as a normal 'not yet created' state, not a crash."],"tags":["filesystem","go","file-not-found"],"backgroundTag":"file-not-found","analyzedSha":"a4447c1563b2df285ab89e76c82f91e1a1a49c1e","analyzedAt":"2026-09-01T15:26:23.972Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}