{"record":{"id":"9217d1576c50f00e","repo":"wavetermdev/waveterm","slug":"getting-file-stats-w","errorCode":null,"errorMessage":"getting file stats: %w","messagePattern":"getting file stats: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/wsh/cmd/wshcmd-wavepath.go","lineNumber":96,"sourceCode":"\t\t}\n\t\treturn nil\n\t}\n\n\tWriteStdout(\"%s\\n\", path)\n\treturn nil\n}\n\nfunc tailLogFile(path string) error {\n\tfile, err := os.Open(path)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"opening log file: %w\", err)\n\t}\n\tdefer file.Close()\n\n\t// Get file size\n\tstat, err := file.Stat()\n\tif err != nil {\n\t\treturn fmt.Errorf(\"getting file stats: %w\", err)\n\t}\n\n\t// Read last 16KB or whole file if smaller\n\treadSize := int64(16 * 1024)\n\tvar offset int64\n\tif stat.Size() > readSize {\n\t\toffset = stat.Size() - readSize\n\t}\n\n\t_, err = file.Seek(offset, 0)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"seeking file: %w\", err)\n\t}\n\n\tbuf := make([]byte, readSize)\n\tn, err := file.Read(buf)\n\tif err != nil && err != io.EOF {\n\t\treturn fmt.Errorf(\"reading file: %w\", err)","sourceCodeStart":78,"sourceCodeEnd":114,"githubUrl":"https://github.com/wavetermdev/waveterm/blob/a4447c1563b2df285ab89e76c82f91e1a1a49c1e/cmd/wsh/cmd/wshcmd-wavepath.go#L78-L114","documentation":"tailLogFile could not Stat the opened log file, which it needs to compute the read offset (last 16KB). With the file already open this is rare and usually means the underlying file vanished or an OS-level I/O problem occurred.","triggerScenarios":"File deleted/rotated between os.Open and Stat (race), file on a network/FUSE mount returning stat errors, or fd exhaustion causing odd failures.","commonSituations":"Aggressive log rotation racing with `wsh wavepath log --tail`; unmounted network volumes hosting the Wave data dir.","solutions":["Re-run the command; transient races resolve on retry.","Check the log directory is on a healthy local filesystem.","Check system fd/memory limits (`ulimit`).","Skip tailing and print the path with `wsh wavepath log`."],"exampleFix":"// before\nstat, err := file.Stat()\n// after\nstat, err := file.Stat()\nif err != nil { return fmt.Errorf(\"getting file stats (was the log rotated?): %w\", err) }","handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"stat, err := file.Stat()\nif err != nil {\n    if _, reopenErr := os.Open(path); reopenErr == nil { return retryTail(path) }\n    return fmt.Errorf(\"getting file stats: %w\", err)\n}","preventionTips":["Keep logs on local, healthy filesystems.","Retry transient stat failures (rotation races).","Monitor disk health if this recurs."],"tags":["filesystem","file-io"],"backgroundTag":"file-stat-failed","analyzedSha":"a4447c1563b2df285ab89e76c82f91e1a1a49c1e","analyzedAt":"2026-09-01T15:26:23.972Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}