Skip to content

Fix crash from unsafe typings#24578

Open
gundermanc wants to merge 1 commit intomainfrom
resume-bug
Open

Fix crash from unsafe typings#24578
gundermanc wants to merge 1 commit intomainfrom
resume-bug

Conversation

@gundermanc
Copy link
Copy Markdown
Member

Summary

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

 ERROR  data.slice is not a function

 file:///Users/gundermanc/.nvm/versions/node/v20.19.6/lib/node_modules/@google/gemini-cli/bundle/interactiveCl
 i-VLQHRXHU.js:20831:83

 -AnsiOutputTex
  t           (file:///Users/gundermanc/.nvm/versions/node/v20.19.6/lib/node_modules/@google/gemini-cli/bundle
              /interactiveCli-VLQHRXHU.js:20831:83)
 -react-stack-bottom-f
  rame               (file:///Users/gundermanc/.nvm/versions/node/v20.19.6/lib/node_modules/@google/gemini-cli
                     /bundle/chunk-UNM3DGTG.js:21469:20)
 -renderWithHook
  s            (file:///Users/gundermanc/.nvm/versions/node/v20.19.6/lib/node_modules/@google/gemini-cli/bundl
               e/chunk-UNM3DGTG.js:12599:24)
 -updateFunctionCompon
  ent                (file:///Users/gundermanc/.nvm/versions/node/v20.19.6/lib/node_modules/@google/gemini-cli
                     /bundle/chunk-UNM3DGTG.js:14922:21)
 -beginWork
          (file:///Users/gundermanc/.nvm/versions/node/v20.19.6/lib/node_modules/@google/gemini-cli/bundle/chu
          nk-UNM3DGTG.js:15889:20)
 -runWithFiberInDE
  V              (file:///Users/gundermanc/.nvm/versions/node/v20.19.6/lib/node_modules/@google/gemini-cli/bun
                 dle/chunk-UNM3DGTG.js:11521:72)
 -performUnitOfWor
  k              (file:///Users/gundermanc/.nvm/versions/node/v20.19.6/lib/node_modules/@google/gemini-cli/bun
                 dle/chunk-UNM3DGTG.js:19278:82)
 -workLoopSync
             (file:///Users/gundermanc/.nvm/versions/node/v20.19.6/lib/node_modules/@google/gemini-cli/bundle/
             chunk-UNM3DGTG.js:19132:43)

@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, 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

  • Crash Fix: Added a safety check in AnsiOutputText to ensure data is an array before calling slice, preventing runtime errors.
  • Type Safety: Updated ToolResultDisplay to use more robust typings and removed unsafe type assertions.
  • Feature Enhancement: Added support for rendering unknown objects as stringified JSON in the tool result display.
Using Gemini Code Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

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)) {
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.

high

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.

Suggested change
} 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)) {
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.

high

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.

Suggested change
if (Array.isArray(resultDisplay)) {
if (Array.isArray(resultDisplay) && (resultDisplay.length === 0 || Array.isArray(resultDisplay[0]))) {

? []
: data.slice(-numLinesRetained)
: [];
const arrayData = Array.isArray(data) ? data : [];
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.

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

this part is a nice improvement!

@gemini-cli gemini-cli bot added the status/need-issue Pull requests that need to have an associated issue. label Apr 2, 2026
Copy link
Copy Markdown
Contributor

@jacob314 jacob314 left a comment

Choose a reason for hiding this comment

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

lgtm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

status/need-issue Pull requests that need to have an associated issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants