Skip to content

fix: Improve error reporting#180

Merged
guyfedwards merged 1 commit intoguyfedwards:masterfrom
majiayu000:fix-170-improve-error-reporting-1231-0740
Jan 23, 2026
Merged

fix: Improve error reporting#180
guyfedwards merged 1 commit intoguyfedwards:masterfrom
majiayu000:fix-170-improve-error-reporting-1231-0740

Conversation

@majiayu000
Copy link
Contributor

Fixes #170

Changes

  • Replace silent tea.Quit calls with user-visible status messages in TUI
  • Replace log.Fatalf/log.Fatal with graceful handling to prevent crashes
  • Fix CLI to exit with code 1 on actual errors (not 0) and print error to stderr
  • Show error context to users instead of silently exiting

@guyfedwards
Copy link
Owner

guyfedwards commented Dec 31, 2025

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)
Copy link
Contributor Author

@majiayu000 majiayu000 Dec 31, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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")
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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")
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Render failures now surface as status messages instead of quitting, improving error visibility and resilience.

Copy link
Contributor Author

@majiayu000 majiayu000 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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")
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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>
@guyfedwards guyfedwards force-pushed the fix-170-improve-error-reporting-1231-0740 branch from 3b38908 to ddea614 Compare January 23, 2026 12:07
@guyfedwards guyfedwards merged commit 82f94d4 into guyfedwards:master Jan 23, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Improve error reporting

2 participants