gemini-cli - ✅(Solved) Fix Unhandled Promise Rejection (ENAMETOOLONG) in robustRealpath when pasting code snippets [2 pull requests]

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…

Error Message

✖ ========================================= This is an unexpected error. Please file a bug report using the /bug tool. CRITICAL: Unhandled Promise Rejection!

Reason: Error: ENAMETOOLONG: name too long, lstat '/data/data/com.termux/files/home/"], dtype=np.uint8) NUM_CHARS = len(ASCII_CHARS)

LUT z kluczami jako Python int (szybszy lookup niż

tuple numpy scalarów) COLOR_LUT = {} for ri in range(8): for gi in range(8): for bi in range(8): key = (ri << 16) | (gi << 8) | bi # int, nie tuple COLOR_LUT[key] = f"033' Stack trace: Error: ENAMETOOLONG: name too long, lstat [...] at Module.realpathSync (node:fs:2760:29) at robustRealpath (file:///data/data/com.termux/files/usr/lib/node_modules/ @google/gemini-cli/bundle/chunk-ETUADTWF.js:41905:16) at resolveToRealPath (file:///data/data/com.termux/files/usr/lib/node_modules/ @google/gemini-cli/bundle/chunk-ETUADTWF.js:41896:10) at checkPermissions (file:///data/data/com.termux/files/usr/lib/node_modules/ @google/gemini-cli/bundle/chunk-AQRXALHQ.js:60877:30)

Root Cause

Description: When pasting a multi-line Python code snippet into the interactive prompt, the CLI incorrectly attempts to parse the raw code as a file path. It prepends the home directory path to the code string and calls lstat. Because the string is extremely long, the OS throws an ENAMETOOLONG error.

Fix Action

Fixed

PR fix notes

PR #25714: fix(paths): handle ENAMETOOLONG and ENOTDIR in robustRealpath

Description (problem / solution / changelog)

Problem

When a user pastes a large multi-line code snippet into the CLI prompt, the auto-file-path detection logic calls robustRealpath on the raw input text (prepended with the home directory). This produces an extremely long string, which causes fs.realpathSync or fs.lstatSync to throw ENAMETOOLONG. Because this error code is not in the allow-list, the error propagates up as an unhandled promise rejection, crashing the entire CLI:

CRITICAL: Unhandled Promise Rejection!
Error: ENAMETOOLONG: name too long, lstat '/home/user/<pasted code...>'

Reported in issue #25696.

Root cause

robustRealpath only handles ENOENT and EISDIR gracefully. Any other error code (including ENAMETOOLONG and ENOTDIR) is re-thrown unhandled.

Fix

  • When realpathSync throws ENAMETOOLONG or ENOTDIR, the string is clearly not a real filesystem path. Return p as-is instead of crashing.
  • When lstatSync throws ENAMETOOLONG or ENOTDIR in the inner catch block, treat them the same as ENOENT/EISDIR (i.e., non-fatal — fall through to parent resolution).

Fixes #25696

Changed files

  • packages/core/src/utils/paths.ts (modified, +15/-3)

PR #25727: fix(core): handle ENAMETOOLONG in robustRealpath

Description (problem / solution / changelog)

Summary

Fixes a crash (Unhandled Promise Rejection) in the CLI when processing extremely long strings (like large Python code snippets) as potential file paths. The crash occurred because the ENAMETOOLONG error from the file system was not being caught in the robustRealpath function.

Details

  • Updated robustRealpath in packages/core/src/utils/paths.ts to catch ENAMETOOLONG in addition to ENOENT and EISDIR.
  • This ensures that if a string is incorrectly identified as an @path command but is too long to be a valid path, the CLI gracefully ignores it instead of crashing.
  • Added a unit test in packages/core/src/utils/paths.test.ts to mock this scenario and prevent regressions.

Related Issues

Fixes https://github.com/google-gemini/gemini-cli/issues/25696

How to Validate

  1. Revert the fix and run npm run build -w @google/gemini-cli-core.
  2. Run npm run start and paste a long quoted string (e.g., @"a" * 5000).
  3. Observe the crash.
  4. Apply the fix and rebuild.
  5. Run npm run start and paste the same string.
  6. Observe that the CLI no longer crashes.

Pre-Merge Checklist

  • Updated relevant documentation and README (if needed)
  • Added/updated tests (if needed)
  • Noted breaking changes (if any)
  • Validated on required platforms/methods:
    • MacOS
      • npm run

Changed files

  • packages/core/src/utils/paths.test.ts (modified, +16/-0)
  • packages/core/src/utils/paths.ts (modified, +5/-3)

Code Example

=========================================
   This is an unexpected error. Please file a bug report
   using the /bug tool.
   CRITICAL: Unhandled Promise Rejection!
   =========================================
   Reason: Error: ENAMETOOLONG: name too long, lstat
   '/data/data/com.termux/files/home/"], dtype=np.uint8)
   NUM_CHARS = len(ASCII_CHARS)
   
   # LUT z kluczami jako Python int (szybszy lookup niż
   tuple numpy scalarów)
   COLOR_LUT = {}
   for ri in range(8):
       for gi in range(8):
           for bi in range(8):
               key = (ri << 16) | (gi << 8) | bi   # int,
   nie tuple
               COLOR_LUT[key] = f"033'
   Stack trace:
   Error: ENAMETOOLONG: name too long, lstat
   [...]
       at Module.realpathSync (node:fs:2760:29)
       at robustRealpath
   (file:///data/data/com.termux/files/usr/lib/node_modules/
   @google/gemini-cli/bundle/chunk-ETUADTWF.js:41905:16)
       at resolveToRealPath
   (file:///data/data/com.termux/files/usr/lib/node_modules/
   @google/gemini-cli/bundle/chunk-ETUADTWF.js:41896:10)
       at checkPermissions
   (file:///data/data/com.termux/files/usr/lib/node_modules/
   @google/gemini-cli/bundle/chunk-AQRXALHQ.js:60877:30)
RAW_BUFFERClick to expand / collapse

Description: When pasting a multi-line Python code snippet into the interactive prompt, the CLI incorrectly attempts to parse the raw code as a file path. It prepends the home directory path to the code string and calls lstat. Because the string is extremely long, the OS throws an ENAMETOOLONG error.

This error is not caught by a try...catch block inside robustRealpath or checkPermissions, which results in a CRITICAL: Unhandled Promise Rejection! and crashes the entire CLI.

Environment:

  • OS: Android / Termux
  • Package: @google/gemini-cli

Steps to Reproduce:

  1. Open Gemini CLI in Termux.
  2. Paste a chunk of raw Python code directly into the chat prompt (without Markdown backticks). Example code that triggered this: "], dtype=np.uint8) NUM_CHARS = len(ASCII_CHARS)...
  3. Submit the prompt.

Expected Behavior: The CLI should treat the input as a standard text prompt. If the CLI has an auto-file-path detection mechanism, it should gracefully catch and ignore file system exceptions like ENAMETOOLONG, ENOENT, or ENOTDIR rather than crashing the application.

Actual Behavior: The CLI crashes immediately with an unhandled promise rejection.

Error Logs:

✖  =========================================
   This is an unexpected error. Please file a bug report
   using the /bug tool.
   CRITICAL: Unhandled Promise Rejection!
   =========================================
   Reason: Error: ENAMETOOLONG: name too long, lstat
   '/data/data/com.termux/files/home/"], dtype=np.uint8)
   NUM_CHARS = len(ASCII_CHARS)
   
   # LUT z kluczami jako Python int (szybszy lookup niż
   tuple numpy scalarów)
   COLOR_LUT = {}
   for ri in range(8):
       for gi in range(8):
           for bi in range(8):
               key = (ri << 16) | (gi << 8) | bi   # int,
   nie tuple
               COLOR_LUT[key] = f"033'
   Stack trace:
   Error: ENAMETOOLONG: name too long, lstat
   [...]
       at Module.realpathSync (node:fs:2760:29)
       at robustRealpath
   (file:///data/data/com.termux/files/usr/lib/node_modules/
   @google/gemini-cli/bundle/chunk-ETUADTWF.js:41905:16)
       at resolveToRealPath
   (file:///data/data/com.termux/files/usr/lib/node_modules/
   @google/gemini-cli/bundle/chunk-ETUADTWF.js:41896:10)
       at checkPermissions
   (file:///data/data/com.termux/files/usr/lib/node_modules/
   @google/gemini-cli/bundle/chunk-AQRXALHQ.js:60877:30)

extent analysis

TL;DR

The most likely fix is to modify the robustRealpath function to catch and handle ENAMETOOLONG errors, preventing the CLI from crashing when pasting multi-line code snippets.

Guidance

  • Verify that the try...catch block in robustRealpath or checkPermissions is not catching the ENAMETOOLONG error, and consider adding a specific catch handler for this error.
  • Check if the lstat call is necessary when the input is a multi-line code snippet, and consider skipping it or using a different approach to handle such inputs.
  • Review the resolveToRealPath function to ensure it's correctly handling cases where the input is not a file path.
  • Consider adding input validation to detect and handle cases where the input is a code snippet rather than a file path.

Example

// Example of catching ENAMETOOLONG error in robustRealpath
try {
  // existing lstat call
} catch (error) {
  if (error.code === 'ENAMETOOLONG') {
    // handle the error, e.g., return an error message or skip the lstat call
  } else {
    throw error;
  }
}

Notes

The provided error logs suggest that the issue is specific to the @google/gemini-cli package on Android/Termux. The fix may need to be applied to the robustRealpath function or other related code in the package.

Recommendation

Apply a workaround by modifying the robustRealpath function to catch and handle ENAMETOOLONG errors, as this is the most direct way to prevent the CLI from crashing when pasting multi-line code snippets.

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