gemini-cli - ✅(Solved) Fix RangeError: Invalid count value: -1 [1 pull requests, 1 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
google-gemini/gemini-cli#25665Fetched 2026-04-20 12:15:44
View on GitHub
Comments
0
Participants
1
Timeline
1
Reactions
0
Author
Participants
Timeline (top)
labeled ×1

Error Message

Keychain initialization encountered an error: Cannot find module '../build/Release/keytar.node' │ │ This is an unexpected error. Please file a bug report using the /bug tool. │ expected no error

PR fix notes

PR #25713: fix(TableRenderer): guard against negative column widths in renderBorder

Description (problem / solution / changelog)

Problem

When the terminal is very narrow, adjustedWidths can contain values that, after the column allocation algorithm scales them down, result in a width of 0 or negative. Calling String.prototype.repeat() with a negative count throws:

RangeError: Invalid count value: -1

This crash was reported in issue #25665.

Root cause

In renderBorder, the border segments are built with:

const borderParts = adjustedWidths.map((w) => char.horizontal.repeat(w));

repeat() requires a non-negative integer. When the terminal is too narrow for the table, adjustedWidths can contain negative values, crashing the renderer.

Fix

Clamp each width to a minimum of 0 before passing it to repeat():

const borderParts = adjustedWidths.map((w) => char.horizontal.repeat(Math.max(0, w)));

This matches the existing defensive pattern already used in renderCell:

const contentWidth = Math.max(0, width - COLUMN_PADDING);

Fixes #25665

Changed files

  • packages/cli/src/ui/utils/TableRenderer.tsx (modified, +1/-1)
RAW_BUFFERClick to expand / collapse

What happened?

Keychain initialization encountered an error: Cannot find module '../build/Release/keytar.node' │ │ Require stack: │ │ - /opt/homebrew/Cellar/gemini-cli/0.38.2/libexec/lib/node_modules/@google/gemini-cli/node_modules/keytar/lib/keytar.js │ │ │ │ ℹ Using FileKeychain fallback for secure storage. │ │ │ │ ℹ Loaded cached credentials. │ │ │ │ ℹ Detected terminal background color: #ffffff │ │ │ │ ℹ Loading extension: superpowers │ │ ℹ Scheduling MCP context refresh... │ │ ℹ Executing MCP context refresh... │ │ ⚠ [STARTUP] Cannot start phase 'load_builtin_commands': phase is already active. Call end() before starting again. │ │ ⚠ [STARTUP] Phase 'load_builtin_commands' was started but never ended. Skipping metrics. │ │ ℹ MCP context refresh complete. │ │ ℹ Authenticated via "oauth-personal". │ │ ℹ │ │ ✖ ========================================= │ │ This is an unexpected error. Please file a bug report using the /bug tool. │ │ CRITICAL: Unhandled Promise Rejection! │ │ ========================================= │ │ Reason: RangeError: Invalid count value: -1 │ │ Stack trace: │ │ RangeError: Invalid count value: -1 │ │ at String.repeat (<anonymous>) │ │ at renderBorder (file:///opt/homebrew/Cellar/gemini-cli/0.38.2/libexec/lib/node_modules/@google/gemini-cli/bundle/chunk-AQRXALHQ.js:37307:89) │ │ at handleContainerNode (file:///opt/homebrew/Cellar/gemini-cli/0.38.2/libexec/lib/node_modules/@google/gemini-cli/bundle/chunk-AQRXALHQ.js:37360:5) │ │ at renderNodeToOutput (file:///opt/homebrew/Cellar/gemini-cli/0.38.2/libexec/lib/node_modules/@google/gemini-cli/bundle/chunk-AQRXALHQ.js:37784:5) │ │ at handleContainerNode (file:///opt/homebrew/Cellar/gemini-cli/0.38.2/libexec/lib/node_modules/@google/gemini-cli/bundle/chunk-AQRXALHQ.js:37469:9) │ │ at renderNodeToOutput (file:///opt/homebrew/Cellar/gemini-cli/0.38.2/libexec/lib/node_modules/@google/gemini-cli/bundle/chunk-AQRXALHQ.js:37784:5) │ │ at handleContainerNode (file:///opt/homebrew/Cellar/gemini-cli/0.38.2/libexec/lib/node_modules/@google/gemini-cli/bundle/chunk-AQRXALHQ.js:37469:9) │ │ at renderNodeToOutput (file:///opt/homebrew/Cellar/gemini-cli/0.38.2/libexec/lib/node_modules/@google/gemini-cli/bundle/chunk-AQRXALHQ.js:37784:5) │ │ at handleContainerNode (file:///opt/homebrew/Cellar/gemini-cli/0.38.2/libexec/lib/node_modules/@google/gemini-cli/bundle/chunk-AQRXALHQ.js:37469:9) │ │ at renderNodeToOutput (file:///opt/homebrew/Cellar/gemini-cli/0.38.2/libexec/lib/node_modules/@google/gemini-cli/bundle/chunk-AQRXALHQ.js:37784:5) (x25)

What did you expect to happen?

expected no error

Client information

  • CLI Version: 0.38.2
  • Git Commit: b0ed611a0
  • Session ID: 3b9a329b-8664-4515-b537-ca1c547e8118
  • Operating System: darwin v25.9.0
  • Sandbox Environment: no sandbox
  • Model Version: auto-gemini-3
  • Auth Type: oauth-personal
  • Memory Usage: 352.8 MB
  • Terminal Name: Unknown
  • Terminal Background: #ffffff
  • Kitty Keyboard Protocol: Unsupported

Login information

Google account

Anything else we need to know?

No response

extent analysis

TL;DR

The issue is likely caused by an unhandled promise rejection due to an invalid count value in the String.repeat function, and a workaround may involve updating the gemini-cli version or modifying the code to handle this edge case.

Guidance

  • The error message indicates a RangeError: Invalid count value: -1 at the String.repeat function, which suggests that the code is attempting to repeat a string with a negative count.
  • To verify the issue, check the code at chunk-AQRXALHQ.js:37307:89 to see where the String.repeat function is being called with a negative count.
  • To mitigate the issue, consider updating the gemini-cli version to a newer release, if available, or modifying the code to handle the case where the count is negative.
  • Additionally, check the terminal background color and other environmental factors to ensure they are not contributing to the issue.

Example

No code example is provided as the issue is related to a specific version of the gemini-cli and the code is not readily available.

Notes

The issue may be specific to the gemini-cli version 0.38.2 and the darwin operating system. Further investigation is needed to determine the root cause and a permanent fix.

Recommendation

Apply a workaround by modifying the code to handle the case where the count is negative, as updating to a fixed version may not be available.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING