Skip to content

fix(XmlPreview): improve XML parsing error handling and return structure - #8860

Merged
vijayh-bruno merged 13 commits into
usebruno:mainfrom
abhishekp-bruno:fix/xml-preview-crash-on-error-component
Aug 19, 2026
Merged

vijayh-bruno merged 13 commits into
usebruno:mainfrom
abhishekp-bruno:fix/xml-preview-crash-on-error-component

Conversation

@abhishekp-bruno

@abhishekp-bruno abhishekp-bruno commented Aug 3, 2026 •

Copy link
Copy Markdown
Contributor

Internal - [BRU-3061]

Fixes: #7735

Description

The XML preview pane renders a "Cannot preview as XML" banner for valid XML whose root element is <error>, e.g.:

<error>
  <code>404</code>
  <message>Not found</message>
</error>

Any API that returns an error envelope in this shape (which is common) can't be previewed as XML at all, even though the response parses perfectly fine.

Problem

The useMemo returned an untagged object that overloaded the error key for two different meanings:

  • failure → { error: 'Failed to parse XML string...' }
  • success → the parsed document tree
    The subsequent check was parsedData.error, which can't distinguish "the parse failed" from "the parse succeeded and the root node happens to be named error". Failure and success share the same key space, so the collision is unavoidable by inspection.

Screenshots

Before After
XML preview showing an error banner for a document with an <error> root XML preview correctly rendering the tree for the same document

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.
  • I've run the claude code review skill locally.

Note: Keeping the PR small and focused helps make it easier to review and merge. If you have multiple changes you want to make, please consider submitting them as separate pull requests.

Publishing to New Package Managers

Please see here for more information.

Summary by CodeRabbit

  • Bug Fixes

    • Improved XML response previews by distinguishing parsing errors from valid XML documents with an error root element.
    • Added clearer messages for malformed, empty, or unsupported XML response data.
    • Preserved accurate rendering for nested elements, attributes, namespaces, declarations, comments, and special characters.
  • Tests

    • Expanded coverage for valid XML documents and various content structures.
    • Added validation for malformed and missing XML response data.

@coderabbitai

coderabbitai Bot commented Aug 3, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

Walkthrough

XmlPreview now separates parsed XML data from parse errors. Valid XML renders as a tree, including roots named error. Invalid input displays structured error messages. Tests cover valid XML features and invalid inputs.

Changes

XML preview handling

Layer / File(s) Summary
Structured XML parsing and validation
packages/bruno-app/src/components/ResponsePane/QueryResult/QueryResultPreview/XmlPreview/index.js, packages/bruno-app/src/components/ResponsePane/QueryResult/QueryResultPreview/XmlPreview/index.spec.js, packages/bruno-app/src/ui/ErrorBanner/index.js
XmlPreview separates parsed data from parse errors and marks the XML tree and error elements for test queries. Tests cover valid XML, malformed input, empty input, and non-string values.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Suggested reviewers: bijin-bruno

Poem

XML enters the preview pane,
Valid trees render without strain.
Parse errors show their message clear,
Tests protect each branch we hear.
Error roots remain valid here.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Linked Issues check ✅ Passed The changes prevent crashes for valid XML responses with an root and add tests for the reported failure case [#7735].
Out of Scope Changes check ✅ Passed All changes support XML preview handling or its test coverage, including test IDs required by the new assertions.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: improved XML parsing error handling and result structure for XmlPreview.
✨ Finishing Touches 💡 1
🛠️ Fix failing CI checks 💡
  • Create stacked PR
  • Commit on current branch
🧪 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.

@helloanoop helloanoop 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.

Left a few comments @abhishekp-bruno

@abhishekp-bruno
abhishekp-bruno force-pushed the fix/xml-preview-crash-on-error-component branch from ff54068 to 86d572c Compare August 5, 2026 11:48
@pull-request-size pull-request-size Bot added size/XL and removed size/L labels Aug 7, 2026
@abhishekp-bruno
abhishekp-bruno force-pushed the fix/xml-preview-crash-on-error-component branch from e5cec66 to 885c39d Compare August 7, 2026 04:17
@abhishekp-bruno
abhishekp-bruno force-pushed the fix/xml-preview-crash-on-error-component branch 2 times, most recently from 5b8818d to a7dee2f Compare August 10, 2026 11:11
Comment thread tests/utils/page/actions.ts Resolved
@abhishekp-bruno
abhishekp-bruno force-pushed the fix/xml-preview-crash-on-error-component branch from 5249e91 to 658ef56 Compare August 10, 2026 13:23
@vijayh-bruno
vijayh-bruno merged commit 8b51a3a into usebruno:main Aug 19, 2026
13 of 15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Crash when switch to preview mode on xml

4 participants