fix: Improve error reporting#180
Conversation
|
Could you please add comments on the github diff for why changes were made, thanks. |
|
|
||
| os.Exit(0) | ||
| // For actual errors, print help and exit with error code | ||
| fmt.Fprintf(os.Stderr, "Error: %s\n\n", err) |
There was a problem hiding this comment.
When flag parsing fails (non-help), surface the error on stderr, show help, and exit non-zero so CLI failures are visible to users/scripts.
| err := c.store.UpsertItem(&i) | ||
| if err != nil { | ||
| log.Fatalf("[commands.go] fetchAllFeeds: %e", err) | ||
| log.Printf("[commands.go] fetchAllFeeds: failed to upsert item: %v", err) |
There was a problem hiding this comment.
Avoid crashing the entire refresh on a single bad item; log the upsert failure and keep processing the rest.
| mdown, err := converter.ConvertString(html) | ||
| if err != nil { | ||
| log.Fatal(err) | ||
| log.Printf("[commands.go] htmlToMd: failed to convert HTML to markdown: %v", err) |
There was a problem hiding this comment.
If HTML→Markdown conversion fails, log and fall back to raw HTML so the entry still renders instead of killing the app.
| fs, err := m.commands.GetAllFeeds() | ||
| if err != nil { | ||
| return tea.Quit | ||
| return m.list.NewStatusMessage(fmt.Sprintf("Error: %s", err)) |
There was a problem hiding this comment.
Show a status message instead of quitting so users see why feeds failed to load.
| err := m.commands.store.ToggleRead(current.ID) | ||
| if err != nil { | ||
| return m, tea.Quit | ||
| return m, m.list.NewStatusMessage(fmt.Sprintf("Error marking read: %s", err)) |
There was a problem hiding this comment.
Keep the TUI alive on toggle-read errors; report the problem in the status area.
| err := m.commands.store.ToggleFavourite(current.ID) | ||
| if err != nil { | ||
| return m, tea.Quit | ||
| return m, m.list.NewStatusMessage(fmt.Sprintf("Error toggling favourite: %s", err)) |
There was a problem hiding this comment.
Same rationale as toggle-read: show an error message instead of exiting the session.
| // LKS: there should be an error message here | ||
| return m, tea.Quit | ||
| m.selectedArticle = nil | ||
| return m, m.list.NewStatusMessage(fmt.Sprintf("Error opening article: %s", err)) |
There was a problem hiding this comment.
If rendering fails, clear selection and display an error to avoid leaving the UI stuck in the article view.
| match, err := regexp.MatchString(o.Regex, url) | ||
| if err != nil { | ||
| return tea.Quit | ||
| log.Printf("[tui.go] OpenLink: invalid regex pattern: %v", err) |
There was a problem hiding this comment.
Skip invalid opener regex patterns with a log so a single bad config entry doesn't terminate the UI.
| if err != nil { | ||
| return m, nil | ||
| m.selectedArticle = nil | ||
| return m, m.list.NewStatusMessage("Error: failed to get article") |
There was a problem hiding this comment.
When the selected item can't be fetched, reset selection and show an error so the user can continue.
| if err != nil { | ||
| return m, tea.Quit | ||
| m.selectedArticle = nil | ||
| return m, m.list.NewStatusMessage("Error rendering article") |
There was a problem hiding this comment.
Render failures now surface as status messages instead of quitting, improving error visibility and resilience.
majiayu000
left a comment
There was a problem hiding this comment.
Added inline notes explaining the intent behind each change.
|
|
||
| os.Exit(0) | ||
| // For actual errors, print help and exit with error code | ||
| fmt.Fprintf(os.Stderr, "Error: %s\n\n", err) |
There was a problem hiding this comment.
Reason: treat real CLI parse errors as failures (exit 1 + stderr) so scripts can detect them; help requests should still be a clean exit.
| err := c.store.UpsertItem(&i) | ||
| if err != nil { | ||
| log.Fatalf("[commands.go] fetchAllFeeds: %e", err) | ||
| log.Printf("[commands.go] fetchAllFeeds: failed to upsert item: %v", err) |
There was a problem hiding this comment.
Avoid crashing the whole app on a single item upsert; log and continue so other feeds still load.
| log.Fatal(err) | ||
| log.Printf("[commands.go] htmlToMd: failed to convert HTML to markdown: %v", err) | ||
| // Return the original HTML if conversion fails | ||
| return html |
There was a problem hiding this comment.
If HTML->MD conversion fails, fall back to original HTML instead of exiting so users still see content.
| fs, err := m.commands.GetAllFeeds() | ||
| if err != nil { | ||
| return tea.Quit | ||
| return m.list.NewStatusMessage(fmt.Sprintf("Error: %s", err)) |
There was a problem hiding this comment.
Replace tea.Quit with a visible status message to avoid silent exits and keep the TUI responsive.
| match, err := regexp.MatchString(o.Regex, url) | ||
| if err != nil { | ||
| return tea.Quit | ||
| log.Printf("[tui.go] OpenLink: invalid regex pattern: %v", err) |
There was a problem hiding this comment.
Invalid opener regex shouldn't kill the UI; log and skip this opener instead.
| if err != nil { | ||
| return m, nil | ||
| m.selectedArticle = nil | ||
| return m, m.list.NewStatusMessage("Error: failed to get article") |
There was a problem hiding this comment.
If the selected article can't be loaded, clear selection and surface an error instead of silently failing.
Replace silent exits and crashes with proper error messages: - main.go: Exit with code 1 on parse errors (not 0), print error to stderr - list.go: Show status messages instead of silent tea.Quit on errors - viewport.go: Return to list view with error message on failures - commands.go: Replace log.Fatal with log.Printf to avoid crashes - tui.go: Skip invalid regex patterns with log instead of crashing Closes guyfedwards#170 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> Signed-off-by: majiayu000 <1835304752@qq.com>
3b38908 to
ddea614
Compare
Fixes #170
Changes
tea.Quitcalls with user-visible status messages in TUIlog.Fatalf/log.Fatalwith graceful handling to prevent crashes