|
| 1 | +# Implementation Plan: Improve Error Display in Webview |
| 2 | + |
| 3 | +## Overview |
| 4 | + |
| 5 | +Currently, `cline.say("error", ...)` displays error text in red. We want to improve this to look more like the "Edit Unsuccessful" display with: |
| 6 | + |
| 7 | +1. A custom title that can be passed as metadata |
| 8 | +2. An expandable/collapsible UI pattern |
| 9 | +3. The error text shown when expanded |
| 10 | + |
| 11 | +## Current Implementation Analysis |
| 12 | + |
| 13 | +### 1. Error Display Flow |
| 14 | + |
| 15 | +- **Backend (Task.ts)**: `say("error", text)` method sends error messages |
| 16 | +- **Frontend (ChatRow.tsx)**: Renders error messages with red text styling |
| 17 | +- **Diff Error Pattern**: Already implements the expandable UI pattern we want to replicate |
| 18 | + |
| 19 | +### 2. Diff Error Implementation (lines 960-1048 in ChatRow.tsx) |
| 20 | + |
| 21 | +The diff_error display has: |
| 22 | + |
| 23 | +- Warning icon with yellow/orange color |
| 24 | +- Bold title ("Edit Unsuccessful") |
| 25 | +- Copy button |
| 26 | +- Expand/collapse chevron |
| 27 | +- Expandable content area showing the error details |
| 28 | + |
| 29 | +## Implementation Steps |
| 30 | + |
| 31 | +### Step 1: Extend the say method signature |
| 32 | + |
| 33 | +**File**: `src/core/task/Task.ts` |
| 34 | + |
| 35 | +The say method already accepts an `options` parameter with metadata support. We need to: |
| 36 | + |
| 37 | +- Document that error messages can include a `title` in metadata |
| 38 | +- No changes needed to the method signature itself |
| 39 | + |
| 40 | +### Step 2: Update ChatRow.tsx to handle enhanced error display |
| 41 | + |
| 42 | +**File**: `webview-ui/src/components/chat/ChatRow.tsx` |
| 43 | + |
| 44 | +Changes needed: |
| 45 | + |
| 46 | +1. Add state for error expansion (similar to `isDiffErrorExpanded`) |
| 47 | +2. Extract metadata from error messages |
| 48 | +3. Render errors with the expandable UI pattern |
| 49 | +4. Use custom title from metadata or default to "Error" |
| 50 | + |
| 51 | +### Step 3: Update translation files |
| 52 | + |
| 53 | +**Files**: All files in `webview-ui/src/i18n/locales/*/chat.json` |
| 54 | + |
| 55 | +Add new translation keys: |
| 56 | + |
| 57 | +- `error.defaultTitle`: Default title when no custom title is provided |
| 58 | +- Keep existing `error` key for backward compatibility |
| 59 | + |
| 60 | +### Step 4: Update existing error calls |
| 61 | + |
| 62 | +Search for all `say("error", ...)` calls and optionally add metadata with custom titles where appropriate. |
| 63 | + |
| 64 | +## Technical Details |
| 65 | + |
| 66 | +### Message Structure |
| 67 | + |
| 68 | +```typescript |
| 69 | +// When calling say with error and custom title: |
| 70 | +await this.say( |
| 71 | + "error", |
| 72 | + "Detailed error message here", |
| 73 | + undefined, // images |
| 74 | + false, // partial |
| 75 | + undefined, // checkpoint |
| 76 | + undefined, // progressStatus |
| 77 | + { |
| 78 | + metadata: { |
| 79 | + title: "Custom Error Title", |
| 80 | + }, |
| 81 | + }, |
| 82 | +) |
| 83 | +``` |
| 84 | + |
| 85 | +### Frontend Rendering Logic |
| 86 | + |
| 87 | +```typescript |
| 88 | +// In ChatRow.tsx, for case "error": |
| 89 | +// 1. Extract title from metadata or use default |
| 90 | +// 2. Render expandable UI similar to diff_error |
| 91 | +// 3. Show error text in expanded section |
| 92 | +``` |
| 93 | + |
| 94 | +## Benefits |
| 95 | + |
| 96 | +1. **Consistency**: Error display matches the existing "Edit Unsuccessful" pattern |
| 97 | +2. **Clarity**: Custom titles provide immediate context about the error type |
| 98 | +3. **User Experience**: Collapsible errors reduce visual clutter |
| 99 | +4. **Flexibility**: Backward compatible - existing error calls continue to work |
| 100 | + |
| 101 | +## Testing Considerations |
| 102 | + |
| 103 | +1. Test with errors that have custom titles |
| 104 | +2. Test with errors without custom titles (should use default) |
| 105 | +3. Test expand/collapse functionality |
| 106 | +4. Test copy button functionality |
| 107 | +5. Verify all translations work correctly |
| 108 | + |
| 109 | +## Migration Strategy |
| 110 | + |
| 111 | +- The implementation is backward compatible |
| 112 | +- Existing `say("error", ...)` calls will continue to work |
| 113 | +- We can gradually update error calls to include custom titles where beneficial |
0 commit comments