Skip to content

Fix error handling in planning tab: display sanitized errors and return control to user - #255

Merged
jbrinkman merged 2 commits into
mainfrom
spec/issue-250-28856
Jul 15, 2026
Merged

Fix error handling in planning tab: display sanitized errors and return control to user#255
jbrinkman merged 2 commits into
mainfrom
spec/issue-250-28856

Conversation

@jbrinkman

Copy link
Copy Markdown
Owner

Summary

This PR fixes error handling in the planning tab to provide a better user experience when prompts fail. Previously, when errors occurred (such as "Improperly formed request" from the ACP stream), users would see raw JSON error messages and the UI would get stuck in a failed state without clear recovery options.

What Changed

Error Message Sanitization

  • Added sanitizeErrorMessage() function that parses JSON-RPC error structures
  • Extracts user-friendly messages from technical error responses
  • Cleans up raw error text and truncates overly long messages
  • Provides fallback message for unknown errors

State Management Improvements

  • Fixed UI state transitions to return to PlanningStateIdle after displaying errors
  • Eliminated persistent PlanningStateFailed state that confused users
  • Users can now immediately retry after errors without manual intervention
  • Prompt indicator properly returns to [planner] > style after errors

Viewport and UX Enhancements

  • Viewport automatically scrolls to show error messages (GotoBottom())
  • Error messages are consistently styled with error coloring
  • Improved error detection to catch both "Error:" and "error:" patterns
  • Preserved all debug logging for troubleshooting

Key Files Modified

  • internal/tui/planning_tab.go - Complete error handling overhaul with sanitization and state management fixes
  • .kiro-krew/specs/issue-250-*.md - Design specification document

Testing

  • ✅ All QA checks pass: formatting, sync check, linting, build
  • ✅ Implementation verified against all 8 acceptance criteria
  • ✅ Application compiles and runs successfully
  • ✅ Error messages are now user-friendly and actionable
  • ✅ UI immediately returns control to users after errors

User Experience Impact

Before:

  • Raw JSON errors like {"code":-32603,"message":"Internal error",...}
  • UI stuck in failed state, unclear if retry is possible
  • Users unsure what action to take after errors

After:

  • Clean error messages like "Error: Improperly formed request"
  • Immediate return to idle state for seamless retry
  • Clear user control and feedback

Closes #250

@coderabbitai

coderabbitai Bot commented Jul 15, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@jbrinkman, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 22 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: a489e54e-ccef-48c3-b406-32a5ad64cc28

📥 Commits

Reviewing files that changed from the base of the PR and between 863e3ae and 2b8ebcc.

📒 Files selected for processing (2)
  • .kiro-krew/specs/issue-250-fix-error-handling-in-planning-tab.md
  • internal/tui/planning_tab.go
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch spec/issue-250-28856

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR improves the Planning tab’s error UX by sanitizing error strings before displaying them to the user and by returning the tab to an idle/retryable state after failures, aligning the UI behavior with Issue #250’s acceptance criteria.

Changes:

  • Introduces sanitizeErrorMessage() to transform technical/raw error payloads into user-facing messages.
  • Adjusts streaming and non-streaming error handlers to display an error message, scroll the viewport to it, and return to PlanningStateIdle.
  • Refines viewport error styling detection to be case-insensitive without repeated lowercasing.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.

File Description
internal/tui/planning_tab.go Adds error sanitization and updates planning tab error handling/state transitions and viewport behavior.
.kiro-krew/specs/issue-250-fix-error-handling-in-planning-tab.md Adds a design spec documenting the problem, approach, and validation steps for Issue #250.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +73 to +95
// Try to parse as JSON-RPC error structure
var jsonError map[string]interface{}
if err := json.Unmarshal([]byte(rawError), &jsonError); err == nil {
// Check for nested error structures: data > message > code
if data, ok := jsonError["data"].(map[string]interface{}); ok {
if message, ok := data["message"].(map[string]interface{}); ok {
if code, ok := message["code"].(string); ok && code != "" {
return code
}
}
// Check for direct message in data
if message, ok := data["message"].(string); ok && message != "" {
return message
}
}
// Check for direct error message field
if message, ok := jsonError["message"].(string); ok && message != "" {
return message
}
if errorMsg, ok := jsonError["error"].(string); ok && errorMsg != "" {
return errorMsg
}
}
Comment on lines +758 to 766
// Sanitize error message for user display
sanitizedError := sanitizeErrorMessage(response.Error)
errorMessage := fmt.Sprintf("Error: %s", sanitizedError)

// Add error message
if response.Error != "" {
pt.currentResponse.WriteString(fmt.Sprintf("\n[Error: %s]", response.Error))
// Preserve accumulated response before displaying error
accumulatedResponse := pt.currentResponse.String()
if accumulatedResponse != "" {
pt.AddMessage("assistant", accumulatedResponse)
}
Comment on lines 801 to +814
if msg.isError {
oldState := pt.state
pt.state = session.PlanningStateFailed
logging.Warn("state transition on error response", "tab_id", pt.id, "from", oldState, "to", pt.state)
pt.AddMessage("assistant", fmt.Sprintf("[Error: %s]", msg.content))

// Sanitize error message for user display
sanitizedError := sanitizeErrorMessage(msg.content)
errorMessage := fmt.Sprintf("Error: %s", sanitizedError)

// Add sanitized error message
pt.AddMessage("assistant", errorMessage)

// Transition to Idle state to allow immediate retry
pt.state = session.PlanningStateIdle
logging.Info("state transition on error response", "tab_id", pt.id, "from", oldState, "to", pt.state)

Comment on lines +66 to +72
// sanitizeErrorMessage parses and formats error messages into user-friendly text.
// It handles JSON-RPC error structures and plain text errors, truncating very long messages.
func sanitizeErrorMessage(rawError string) string {
if rawError == "" {
return "An unknown error occurred"
}

- Handle prefixed JSON errors (e.g., 'failed to send prompt: {...}')
- Support data field as string (most common JSON-RPC case)
- Set state to Idle BEFORE AddMessage in both error paths

Addresses Copilot review feedback on PR #255:
- Fixes sanitization failures on wrapped/prefixed JSON
- Prevents incorrect state persistence via saveSessionState()
- Ensures session state is correct after error handling

Signed-off-by: Joseph Brinkman <joe.brinkman@improving.com>
@jbrinkman
jbrinkman merged commit e17a8d0 into main Jul 15, 2026
2 checks passed
@jbrinkman
jbrinkman deleted the spec/issue-250-28856 branch July 15, 2026 14:20
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.

Fix error handling in planning tab: display sanitized errors and return control to user

2 participants