Skip to content

Improve container engine error#72

Open
gtsiolis wants to merge 1 commit intomainfrom
george/improve-container-engine-error
Open

Improve container engine error#72
gtsiolis wants to merge 1 commit intomainfrom
george/improve-container-engine-error

Conversation

@gtsiolis
Copy link
Member

@gtsiolis gtsiolis commented Mar 3, 2026

See DES-152 for more context.

BEFORE AFTER
Screenshot 2026-03-04 at 01 50 01 Screenshot 2026-03-04 at 01 48 36

@coderabbitai
Copy link

coderabbitai bot commented Mar 3, 2026

📝 Walkthrough

Walkthrough

Updates the ErrorDisplay component to accept a width parameter for text wrapping. The View method signature changes to accept maxWidth, enabling multi-line rendering with proper text wrapping. All callers are updated to pass the content width.

Changes

Cohort / File(s) Summary
ErrorDisplay Implementation
internal/ui/components/error_display.go
Adds maxWidth parameter to View method; introduces softWrap helper for word-boundary text wrapping; updates Summary rendering to multi-line with indentation alignment; updates Action rendering to support multiple actions with secondary styling for non-primary actions.
Caller Updates
internal/ui/app.go, internal/ui/components/error_display_test.go
Updates all View method call sites to pass width parameter (contentWidth in app.go, 80 in tests); reflects signature change from View() to View(maxWidth int).

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

🚥 Pre-merge checks | ✅ 1 | ❌ 1

❌ Failed checks (1 inconclusive)

Check name Status Explanation Resolution
Title check ❓ Inconclusive The title is vague and does not clearly convey the specific change; 'Improve container engine error' uses imprecise language that could refer to many things. Consider a more specific title like 'Add text wrapping to error messages' or 'Improve error message formatting' that clearly describes the core change.
✅ Passed checks (1 passed)
Check name Status Explanation
Description check ✅ Passed The description references an issue (DES-152) and includes before/after screenshots showing improved error message formatting with complete text visibility.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch george/improve-container-engine-error

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 and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
internal/ui/components/error_display_test.go (1)

35-50: Add a narrow-width regression test for wrapping behavior.

These assertions validate content presence, but they don’t guard the new width-constrained behavior (especially long-token wrapping). A focused test for small widths would prevent regressions in this PR’s core behavior.

Suggested test addition
+func TestSoftWrap_HardBreaksLongWord(t *testing.T) {
+	t.Parallel()
+
+	lines := softWrap("unix:///var/run/docker.sock", 8)
+	for _, line := range lines {
+		if len(line) > 8 {
+			t.Fatalf("expected hard-wrapped segment length <= 8, got %q", line)
+		}
+	}
+}

Based on learnings: “Ensure tests verify the separate rendering paths and avoid unintended coupling to the plain-output formatting.”

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@internal/ui/components/error_display_test.go` around lines 35 - 50, Add a
focused unit test in error_display_test.go that constructs the same error
display (the existing e variable/instance) but calls View with a small width
(e.g., 20 or similar) and asserts that the output preserves the title, summary
and detail while also verifying long-token wrapping behavior (e.g., a very long
word is broken across lines) and that action lines (labels like "Start Docker:"
and values like "open -a Docker") render on separate lines or wrap as expected;
target the View(width int) method and the same title/summary/detail/action
strings to ensure the width-constrained rendering path is exercised separately
from the plain-output formatting.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@internal/ui/components/error_display.go`:
- Around line 91-104: The softWrap loop currently appends overlong tokens
(variable word) directly and can exceed maxWidth; update the logic in the
softWrap routine (the for _, word := range words loop using current, maxWidth,
lines) to detect when len(word) > maxWidth and instead split that token into
chunks that fit maxWidth (using rune-aware slicing) appending each chunk as its
own line (flushing current first if non-empty), and when a chunk exactly fills a
line start a new line; ensure remaining partial chunk is written into current
rather than appended raw so no produced line exceeds maxWidth.

---

Nitpick comments:
In `@internal/ui/components/error_display_test.go`:
- Around line 35-50: Add a focused unit test in error_display_test.go that
constructs the same error display (the existing e variable/instance) but calls
View with a small width (e.g., 20 or similar) and asserts that the output
preserves the title, summary and detail while also verifying long-token wrapping
behavior (e.g., a very long word is broken across lines) and that action lines
(labels like "Start Docker:" and values like "open -a Docker") render on
separate lines or wrap as expected; target the View(width int) method and the
same title/summary/detail/action strings to ensure the width-constrained
rendering path is exercised separately from the plain-output formatting.

ℹ️ Review info

Configuration used: Repository UI (base), Organization UI (inherited)

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f8adc60 and c840618.

📒 Files selected for processing (3)
  • internal/ui/app.go
  • internal/ui/components/error_display.go
  • internal/ui/components/error_display_test.go

Comment on lines +91 to +104
for _, word := range words {
if current.Len() == 0 {
current.WriteString(word)
continue
}
if current.Len()+1+len(word) > maxWidth {
lines = append(lines, current.String())
current.Reset()
current.WriteString(word)
} else {
current.WriteByte(' ')
current.WriteString(word)
}
}
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

softWrap still emits overlong words, so width limits can be violated.

Overlong tokens are appended as-is when they exceed maxWidth, so narrow views can still overflow/truncate paths and socket strings. That conflicts with the helper contract and the intent of width-constrained rendering.

Proposed fix
 func softWrap(text string, maxWidth int) []string {
 	if maxWidth <= 0 || len(text) <= maxWidth {
 		return []string{text}
 	}

 	words := strings.Fields(text)
 	if len(words) == 0 {
 		return []string{text}
 	}

 	var lines []string
 	var current strings.Builder
+	flushCurrent := func() {
+		if current.Len() > 0 {
+			lines = append(lines, current.String())
+			current.Reset()
+		}
+	}

 	for _, word := range words {
+		for len(word) > maxWidth {
+			flushCurrent()
+			lines = append(lines, word[:maxWidth])
+			word = word[maxWidth:]
+		}
+
 		if current.Len() == 0 {
 			current.WriteString(word)
 			continue
 		}
 		if current.Len()+1+len(word) > maxWidth {
-			lines = append(lines, current.String())
-			current.Reset()
+			flushCurrent()
 			current.WriteString(word)
 		} else {
 			current.WriteByte(' ')
 			current.WriteString(word)
 		}
 	}
-	if current.Len() > 0 {
-		lines = append(lines, current.String())
-	}
+	flushCurrent()

 	return lines
 }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
for _, word := range words {
if current.Len() == 0 {
current.WriteString(word)
continue
}
if current.Len()+1+len(word) > maxWidth {
lines = append(lines, current.String())
current.Reset()
current.WriteString(word)
} else {
current.WriteByte(' ')
current.WriteString(word)
}
}
func softWrap(text string, maxWidth int) []string {
if maxWidth <= 0 || len(text) <= maxWidth {
return []string{text}
}
words := strings.Fields(text)
if len(words) == 0 {
return []string{text}
}
var lines []string
var current strings.Builder
flushCurrent := func() {
if current.Len() > 0 {
lines = append(lines, current.String())
current.Reset()
}
}
for _, word := range words {
for len(word) > maxWidth {
flushCurrent()
lines = append(lines, word[:maxWidth])
word = word[maxWidth:]
}
if current.Len() == 0 {
current.WriteString(word)
continue
}
if current.Len()+1+len(word) > maxWidth {
flushCurrent()
current.WriteString(word)
} else {
current.WriteByte(' ')
current.WriteString(word)
}
}
flushCurrent()
return lines
}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@internal/ui/components/error_display.go` around lines 91 - 104, The softWrap
loop currently appends overlong tokens (variable word) directly and can exceed
maxWidth; update the logic in the softWrap routine (the for _, word := range
words loop using current, maxWidth, lines) to detect when len(word) > maxWidth
and instead split that token into chunks that fit maxWidth (using rune-aware
slicing) appending each chunk as its own line (flushing current first if
non-empty), and when a chunk exactly fills a line start a new line; ensure
remaining partial chunk is written into current rather than appended raw so no
produced line exceeds maxWidth.

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.

1 participant