Conversation
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request addresses a runtime crash caused by unsafe array operations and improves the overall type safety of the tool result display component. It also enhances the UI by providing a fallback mechanism to render arbitrary objects as JSON, ensuring better visibility for unexpected data structures. Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request improves the robustness and type safety of the ToolResultDisplay and AnsiOutput components. Key changes include transitioning the resultDisplay prop to a core type, removing unsafe type assertions, and implementing a fallback to render unknown objects as stringified JSON. Review feedback highlights a critical issue where the current Array.isArray checks are too broad; since AnsiOutput expects an array of arrays, passing a flat array of strings would cause a runtime crash. It is recommended to narrow these checks to verify the nested structure of the data.
| /> | ||
| ); | ||
| } else { | ||
| } else if (Array.isArray(contentData)) { |
There was a problem hiding this comment.
The check Array.isArray(contentData) is too broad. If contentData is a flat array of strings (e.g., string[]), it will be passed to AnsiOutputText, which eventually calls .map() on the individual elements (expecting them to be AnsiLine arrays). This will cause a TypeError: line.map is not a function. By ensuring the first element is also an array (or the array is empty), you can safely distinguish AnsiOutput from other array types and allow them to fall through to the JSON.stringify fallback.
| } else if (Array.isArray(contentData)) { | |
| } else if (Array.isArray(contentData) && (contentData.length === 0 || Array.isArray(contentData[0]))) { |
| @@ -178,18 +178,13 @@ export const ToolResultDisplay: React.FC<ToolResultDisplayProps> = ({ | |||
| // Virtualized path for large ANSI arrays | |||
| if (Array.isArray(resultDisplay)) { | |||
There was a problem hiding this comment.
Similar to the check in renderContent, this condition should verify that the array contains nested arrays (ANSI lines). If a flat array is passed here, the virtualized ScrollableList will attempt to render items using AnsiLineText, leading to a crash when it tries to map over a string. Narrowing this check allows non-ANSI arrays to fall through to the standard rendering path where they can be handled by the JSON.stringify fallback.
| if (Array.isArray(resultDisplay)) { | |
| if (Array.isArray(resultDisplay) && (resultDisplay.length === 0 || Array.isArray(resultDisplay[0]))) { |
| ? [] | ||
| : data.slice(-numLinesRetained) | ||
| : []; | ||
| const arrayData = Array.isArray(data) ? data : []; |
There was a problem hiding this comment.
adding checks like this makes it hard for us to get this code right as you are now quietly not rendering anything with no logging or indication of what went wrong.
Can you try to root cause the issue a little rather than papering it over?
| 'fileDiff' in contentData | ||
| ) { | ||
| content = ( | ||
| <DiffRenderer |
There was a problem hiding this comment.
this part is a nice improvement!

Summary
Fixes the following crash stack and updates typings to prevent similar issues in the future.