fix: XML preview crash when response contains <error> root element#7749
fix: XML preview crash when response contains <error> root element#7749abhishek-bruno wants to merge 1 commit intousebruno:mainfrom
Conversation
Updated the error checking logic to ensure that the error property is a string, allowing for better distinction between parsing errors and valid XML structures containing an <error> root element.
WalkthroughFixed XML preview error detection in Changes
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~3 minutes Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In
`@packages/bruno-app/src/components/ResponsePane/QueryResult/QueryResultPreview/XmlPreview/index.js`:
- Around line 20-21: The current check treats any parsed object with an error
key as a parse failure and misclassifies valid XML like <error>...</error>;
change the parser to attach a dedicated parse-error field (e.g., __parseError or
parseError) to the parse result when parsing fails, and update the detection
logic to check that dedicated field (replace checks on parsedData.error with
parsedData.__parseError or parsedData.parseError). Locate where parsedData is
produced and where the condition is evaluated (references: parsedData) and
ensure only the dedicated parse-error field is used to detect parse failures so
legitimate <error> elements are preserved.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 3258f0ce-8f9c-4834-916a-2cf195a4787a
📒 Files selected for processing (1)
packages/bruno-app/src/components/ResponsePane/QueryResult/QueryResultPreview/XmlPreview/index.js
| // Check for parsing error (must be a string to distinguish from XML with an <error> root element) | ||
| if (parsedData && typeof parsedData === 'object' && typeof parsedData.error === 'string') { |
There was a problem hiding this comment.
Use a dedicated parse-error field instead of error key collision
Line 21 still misclassifies valid XML like <error>Unauthorized</error> as a parse failure, because parsed XML can legitimately produce { error: '...' }.
💡 Suggested fix
- const parsedData = useMemo(() => {
+ const parsedResult = useMemo(() => {
if (typeof data !== 'string') {
- return { error: 'Invalid input. Expected an XML string.' };
+ return { data: null, parseError: 'Invalid input. Expected an XML string.' };
}
const parsed = parseXMLString(data);
if (parsed === null) {
- return { error: 'Failed to parse XML string. Invalid XML format.' };
+ return { data: null, parseError: 'Failed to parse XML string. Invalid XML format.' };
}
- return parsed;
+ return { data: parsed, parseError: null };
}, [data]);
- if (parsedData && typeof parsedData === 'object' && typeof parsedData.error === 'string') {
+ if (parsedResult.parseError) {
return (
<div className="px-2">
- <ErrorBanner errors={[{ title: 'Cannot preview as XML', message: parsedData.error }]} />
+ <ErrorBanner errors={[{ title: 'Cannot preview as XML', message: parsedResult.parseError }]} />
</div>
);
}
+
+ const parsedData = parsedResult.data;🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In
`@packages/bruno-app/src/components/ResponsePane/QueryResult/QueryResultPreview/XmlPreview/index.js`
around lines 20 - 21, The current check treats any parsed object with an error
key as a parse failure and misclassifies valid XML like <error>...</error>;
change the parser to attach a dedicated parse-error field (e.g., __parseError or
parseError) to the parse result when parsing fails, and update the detection
logic to check that dedicated field (replace checks on parsedData.error with
parsedData.__parseError or parsedData.parseError). Locate where parsedData is
produced and where the condition is evaluated (references: parsedData) and
ensure only the dedicated parse-error field is used to detect parse failures so
legitimate <error> elements are preserved.
|
@abhishek-bruno is there anyway we can test this behaviour? |
| // Check for parsing error | ||
| if (parsedData && typeof parsedData === 'object' && parsedData.error) { | ||
| // Check for parsing error (must be a string to distinguish from XML with an <error> root element) | ||
| if (parsedData && typeof parsedData === 'object' && typeof parsedData.error === 'string') { |
There was a problem hiding this comment.
@abhishek-bruno How are we representing the xml error now in the UI? what is the typeof error we receive.
Description
JIRA
Test plan
Send a request that returns an XML error response like:
Fixes #7735
Contribution Checklist:
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.