Skip to content

feat(app): scroll to and highlight error line on script error - #8183

Merged
sid-bruno merged 3 commits into
usebruno:mainfrom
pooja-bruno:feat/focus-error-line-in-editor
Jun 15, 2026
Merged

sid-bruno merged 3 commits into
usebruno:mainfrom
pooja-bruno:feat/focus-error-line-in-editor

Conversation

@pooja-bruno

@pooja-bruno pooja-bruno commented Jun 4, 2026 •

Copy link
Copy Markdown
Collaborator

Description

JIRA

Contribution Checklist:

  • I've used AI significantly to create this pull request
  • The pull request only addresses one issue or adds one feature.
  • The pull request does not introduce any breaking changes
  • I have added screenshots or gifs to help explain the change if applicable.
  • I have read the contribution guidelines.
  • Create an issue and link to the pull request.
Screen.Recording.2026-06-04.at.4.43.11.PM.mov

Summary by CodeRabbit

  • New Features
    • Script editors now auto-focus and highlight the relevant error line in pre-request, post-response, and test scripts, with a temporary “flash” to draw attention.
    • Error-line highlighting includes gutter emphasis, and the motion animation is disabled when reduced-motion is enabled.
    • Clicking a script error card can jump to the correct tab/editor and scroll the line into view.
  • Tests
    • End-to-end coverage added for highlighting, auto-clear, re-triggering, navigation, and ensuring long errors scroll into view.

@coderabbitai

coderabbitai Bot commented Jun 4, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: dab53794-cd67-4796-b642-df5605b8443a

📥 Commits

Reviewing files that changed from the base of the PR and between 421ae39 and 93ba26c.

📒 Files selected for processing (1)
  • packages/bruno-app/src/components/RequestPane/Tests/index.js
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/bruno-app/src/components/RequestPane/Tests/index.js

Walkthrough

Adds Redux signals, a focus utility, and a hook to scroll CodeMirror editors to an error line and apply a transient CSS flash; components dispatch focus on error-card navigation and E2E tests validate highlight, auto-clear, re-trigger, and scrolling.

Changes

Error-line focus and highlighting

Layer / File(s) Summary
Styling foundation and Redux state management
packages/bruno-app/src/components/CodeEditor/StyledWrapper.js, packages/bruno-app/src/providers/ReduxStore/slices/tabs.js
CSS keyframes cm-error-line-flash and gutter danger styling; Redux setFocusErrorLine / clearFocusErrorLine reducers add/reset per-tab focusErrorLine (scriptPhase, line, requestedAt).
Highlight utility and focus hook
packages/bruno-app/src/utils/codemirror/focusErrorLine.js, packages/bruno-app/src/hooks/useFocusErrorLine/index.js
focusErrorLine scrolls to a 1-based line, adds/removes line + gutter classes with timeout and safe cleanup; useFocusErrorLine subscribes to tabs slice, gates by visibility and scriptPhase, invokes the util, and clears the Redux signal.
Error card navigation with focus dispatch
packages/bruno-app/src/components/ResponsePane/ScriptError/index.js
ScriptError reads errorContext.errorLine and dispatches setFocusErrorLine (uid, scriptPhase, line, requestedAt) when navigating to collection/folder/request script editors.
Script and test editor integration across panes
packages/bruno-app/src/components/CollectionSettings/Script/index.js, packages/bruno-app/src/components/CollectionSettings/Tests/index.js, packages/bruno-app/src/components/FolderSettings/Script/index.js, packages/bruno-app/src/components/FolderSettings/Tests/index.js, packages/bruno-app/src/components/RequestPane/Script/index.js, packages/bruno-app/src/components/RequestPane/Tests/index.js
Components import and call useFocusErrorLine for pre-request/post-response (scriptPhase: 'pre-request'|'post-response') and tests (scriptPhase: 'test'), passing uid, editor refs, and visibility gates tied to active tab.
Test fixture and E2E validation
tests/script-errors/fixtures/collections/script-errors-test/long-pre-request-error.bru, tests/script-errors/focus-error-line.spec.ts
Fixture triggers a long pre-request script error; Playwright tests verify highlight appears, auto-clears, re-triggers, works across phases, scrolls for long scripts, and contains expected text.

Sequence Diagram

sequenceDiagram
  participant User
  participant ScriptError as ScriptError Card
  participant Redux
  participant useFocusErrorLine as useFocusErrorLine Hook
  participant focusErrorLine as focusErrorLine Util
  participant Editor as CodeMirror Editor
  User->>ScriptError: Click error file path
  ScriptError->>Redux: dispatch setFocusErrorLine(uid, scriptPhase, line, requestedAt)
  activate Redux
  Redux->>Redux: Store focusErrorLine on tab
  deactivate Redux
  useFocusErrorLine->>Redux: select focusErrorLine signal
  activate useFocusErrorLine
  useFocusErrorLine->>useFocusErrorLine: check tab visible + phase match
  useFocusErrorLine->>focusErrorLine: call focusErrorLine(editor, line)
  activate focusErrorLine
  focusErrorLine->>Editor: scroll to line + add cm-error-line-flash classes
  focusErrorLine->>focusErrorLine: schedule removal after 3s
  deactivate focusErrorLine
  focusErrorLine-->>User: line highlights and animates
  focusErrorLine->>Editor: remove cm-error-line-flash classes after timeout
  useFocusErrorLine->>Redux: dispatch clearFocusErrorLine(uid)
  deactivate useFocusErrorLine
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Suggested reviewers

  • helloanoop
  • lohit-bruno
  • bijin-bruno
  • sid-bruno

Poem

A line glows red, then fades away,
Redux whispers where it lay.
The editor scrolls, the spotlight plays,
Three seconds bright in flashing blaze.
Error found — now done with the delay.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main feature: automatically scrolling to and highlighting error lines when script errors occur, which aligns with the comprehensive changes across multiple editor components and the CodeMirror styling updates.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick comments (4)
packages/bruno-app/src/utils/codemirror/focusErrorLine.js (1)

6-12: 💤 Low value

Consider early return for empty editors.

When lineCount is 0, the clamping logic sets line = 0, but the editor has no lines. While the try/catch below handles this safely, an explicit early return would be clearer:

 export const focusErrorLine = (editor, line1Based, { durationMs = 3000 } = {}) => {
   if (!editor || typeof line1Based !== 'number' || Number.isNaN(line1Based)) {
     return () => {};
   }
 
   const lineCount = editor.lineCount();
+  if (lineCount === 0) {
+    return () => {};
+  }
   const line = Math.max(0, Math.min(line1Based - 1, lineCount - 1));
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/bruno-app/src/utils/codemirror/focusErrorLine.js` around lines 6 -
12, The function focusErrorLine should explicitly handle empty editors: after
calling editor.lineCount() check if lineCount === 0 and return a no-op cleanup
immediately instead of continuing; update the logic around the line variable
(computed from line1Based and lineCount) only after this check so you don't
clamp against an empty editor, and keep the existing try/catch for safety.
tests/script-errors/focus-error-line.spec.ts (3)

84-86: 💤 Low value

Consider moving locator definition inside test steps for consistency.

Tests 1, 2, 4, 5, and 6 define their flashedLine locator inside the relevant test step, but test 3 defines it outside at lines 84-86. Moving it into the first step would maintain consistency with the other tests.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tests/script-errors/focus-error-line.spec.ts` around lines 84 - 86, Move the
flashedLine locator definition inside the first test step to match the pattern
used by Tests 1, 2, 4, 5, and 6: instead of defining const flashedLine =
page.getByTestId('pre-request-script-editor').locator('.CodeMirror
.cm-error-line-flash') at the top of the test file, declare that same const
within the first step/block of Test 3 so the locator is created in-context and
consistently with the other tests.

163-165: ⚡ Quick win

Prefer type guard over non-null assertion.

Line 164 checks that scrollTop is not null, but line 165 uses the non-null assertion operator !. TypeScript best practice is to use a type guard or conditional instead.

♻️ Suggested refactor
       const scrollTop = await getScrollerScrollTop(page, 'pre-request-script-editor');
       expect(scrollTop).not.toBeNull();
-      expect(scrollTop!).toBeGreaterThan(0);
+      expect(scrollTop).toBeGreaterThan(0);

Playwright's expect() will narrow the type after the .not.toBeNull() check, making the assertion operator unnecessary.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tests/script-errors/focus-error-line.spec.ts` around lines 163 - 165, The
test uses a non-null assertion on scrollTop after already asserting it is not
null; change this to a type-safe check by removing the `!` and relying on
Playwright's expect() narrowing (or add an explicit type guard like `if
(scrollTop === null) throw`), so update the assertions around the
getScrollerScrollTop(...) result (`scrollTop`) in focus-error-line.spec.ts to
avoid the non-null operator and use a proper type guard or rely on expect's
narrowing before calling toBeGreaterThan.

73-74: ⚡ Quick win

Comment/timeout mismatch.

The comment mentions "Allow 4s" but the timeout is 5000ms (5s). Update the comment to match.

📝 Suggested fix
-      // Helper's default duration is 3000ms. Allow 4s for animation end + cleanup.
+      // Helper's default duration is 3000ms. Allow 5s for animation end + cleanup.
       await expect(flashedLine).toHaveCount(0, { timeout: 5000 });
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tests/script-errors/focus-error-line.spec.ts` around lines 73 - 74, The
inline comment is incorrect — it says "Allow 4s" while the test uses a 5000ms
timeout; update the comment to reflect 5s (or otherwise change the timeout to
4000ms if you prefer) so the comment and code agree; specifically edit the
comment above the expect(flashedLine).toHaveCount(0, { timeout: 5000 })
assertion (referencing flashedLine and toHaveCount) to state "Allow 5s for
animation end + cleanup."
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@packages/bruno-app/src/utils/codemirror/focusErrorLine.js`:
- Around line 6-12: The function focusErrorLine should explicitly handle empty
editors: after calling editor.lineCount() check if lineCount === 0 and return a
no-op cleanup immediately instead of continuing; update the logic around the
line variable (computed from line1Based and lineCount) only after this check so
you don't clamp against an empty editor, and keep the existing try/catch for
safety.

In `@tests/script-errors/focus-error-line.spec.ts`:
- Around line 84-86: Move the flashedLine locator definition inside the first
test step to match the pattern used by Tests 1, 2, 4, 5, and 6: instead of
defining const flashedLine =
page.getByTestId('pre-request-script-editor').locator('.CodeMirror
.cm-error-line-flash') at the top of the test file, declare that same const
within the first step/block of Test 3 so the locator is created in-context and
consistently with the other tests.
- Around line 163-165: The test uses a non-null assertion on scrollTop after
already asserting it is not null; change this to a type-safe check by removing
the `!` and relying on Playwright's expect() narrowing (or add an explicit type
guard like `if (scrollTop === null) throw`), so update the assertions around the
getScrollerScrollTop(...) result (`scrollTop`) in focus-error-line.spec.ts to
avoid the non-null operator and use a proper type guard or rely on expect's
narrowing before calling toBeGreaterThan.
- Around line 73-74: The inline comment is incorrect — it says "Allow 4s" while
the test uses a 5000ms timeout; update the comment to reflect 5s (or otherwise
change the timeout to 4000ms if you prefer) so the comment and code agree;
specifically edit the comment above the expect(flashedLine).toHaveCount(0, {
timeout: 5000 }) assertion (referencing flashedLine and toHaveCount) to state
"Allow 5s for animation end + cleanup."

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 235e9ede-4246-41dc-bf81-6d3dc1c94708

📥 Commits

Reviewing files that changed from the base of the PR and between a8b938f and 91b5098.

📒 Files selected for processing (13)
  • packages/bruno-app/src/components/CodeEditor/StyledWrapper.js
  • packages/bruno-app/src/components/CollectionSettings/Script/index.js
  • packages/bruno-app/src/components/CollectionSettings/Tests/index.js
  • packages/bruno-app/src/components/FolderSettings/Script/index.js
  • packages/bruno-app/src/components/FolderSettings/Tests/index.js
  • packages/bruno-app/src/components/RequestPane/Script/index.js
  • packages/bruno-app/src/components/RequestPane/Tests/index.js
  • packages/bruno-app/src/components/ResponsePane/ScriptError/index.js
  • packages/bruno-app/src/hooks/useFocusErrorLine/index.js
  • packages/bruno-app/src/providers/ReduxStore/slices/tabs.js
  • packages/bruno-app/src/utils/codemirror/focusErrorLine.js
  • tests/script-errors/fixtures/collections/script-errors-test/long-pre-request-error.bru
  • tests/script-errors/focus-error-line.spec.ts

sid-bruno
sid-bruno previously approved these changes Jun 9, 2026
sid-bruno
sid-bruno previously approved these changes Jun 10, 2026
@sid-bruno
sid-bruno merged commit b73bf9d into usebruno:main Jun 15, 2026
18 of 20 checks passed
abhishekp-bruno pushed a commit to abhishekp-bruno/bruno that referenced this pull request Jun 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants