{"record":{"id":"23befc6f54c3861a","repo":"wavetermdev/waveterm","slug":"opening-log-file-w","errorCode":null,"errorMessage":"opening log file: %w","messagePattern":"opening log file: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/wsh/cmd/wshcmd-wavepath.go","lineNumber":89,"sourceCode":"\t\treturn fmt.Errorf(\"getting path: %w\", err)\n\t}\n\n\tif tail && pathType == \"log\" {\n\t\terr = tailLogFile(path)\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"tailing log file: %w\", err)\n\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 {","sourceCodeStart":71,"sourceCodeEnd":107,"githubUrl":"https://github.com/wavetermdev/waveterm/blob/a4447c1563b2df285ab89e76c82f91e1a1a49c1e/cmd/wsh/cmd/wshcmd-wavepath.go#L71-L107","documentation":"tailLogFile could not os.Open the log file at the path returned by the server. Since --tail reads the log directly from the local filesystem, this fails when the file is absent, unreadable, or the path is a directory.","triggerScenarios":"`wsh wavepath log --tail` when the log file has been deleted/rotated, the user lacks read permission, the path doesn't exist, or the path is a directory.","commonSituations":"Log rotation, fresh Wave install with no waveterm.log yet, running wsh under a different user (sudo/CI) than the terminal owner.","solutions":["Verify the file exists: `ls -l \"$(wsh wavepath log)\"`.","Fix permissions (`chmod`/run as terminal owner).","Ensure Wave has actually written a log file (start the terminal once).","Retry after rotation completes."],"exampleFix":"// before\nfile, err := os.Open(path)\n// after\nif _, err := os.Stat(path); os.IsNotExist(err) { return fmt.Errorf(\"log file %s does not exist yet\", path) }","handlingStrategy":"validation","validationCode":"if _, err := os.Stat(path); err != nil { /* skip tailing */ }","typeGuard":"func canOpen(path string) bool { f, err := os.Open(path); if err != nil { return false }; f.Close(); return true }","tryCatchPattern":"if err := tailLogFile(path); err != nil { log.Printf(\"tail skipped: %v\", err); return nil }","preventionTips":["Confirm the log file exists before tailing (fresh installs may not have one).","Run wsh as the same user that owns the terminal.","Account for log rotation in scripts."],"tags":["filesystem","file-io","permissions"],"backgroundTag":"file-open-failed","analyzedSha":"a4447c1563b2df285ab89e76c82f91e1a1a49c1e","analyzedAt":"2026-09-01T15:26:23.972Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}