gemini-cli - 💡(How to fix) Fix [Bug] CLI crashes with ENAMETOOLONG when pasting long strings into prompt [3 comments, 2 participants]

Official PRs (…)
ON THIS PAGE

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#26368Fetched 2026-05-03 04:52:33
View on GitHub
Comments
3
Participants
2
Timeline
7
Reactions
0
Author
Timeline (top)
commented ×3cross-referenced ×1labeled ×1mentioned ×1

Error Message

CRITICAL: Unhandled Promise Rejection! Reason: Error: ENAMETOOLONG: name too long, lstat '/Users/huyitao/paste/...[huge string]' at Module.lstatSync (node:fs:1713:25) at robustRealpath (/Users/huyitao/gemini-cli/packages/core/src/utils/paths.ts:389:25) at resolveToRealPath (/Users/huyitao/gemini-cli/packages/core/src/utils/paths.ts:372:10) at checkPermissions (/Users/huyitao/gemini-cli/packages/cli/src/ui/hooks/atCommandProcessor.ts:191:28)

Root Cause

The root cause is that the input parser (parseAllAtCommands in packages/cli/src/ui/hooks/atCommandProcessor.ts) identifies strings starting with @ as potential file paths and passes them to resolveToRealPath (in packages/core/src/utils/paths.ts). resolveToRealPath calls fs.lstatSync on the entire string without validating its length. If the string is longer than the operating system's maximum path length (e.g., 1024 characters on macOS), Node.js throws Error: ENAMETOOLONG.

Code Example

CRITICAL: Unhandled Promise Rejection!
Reason: Error: ENAMETOOLONG: name too long, lstat '/Users/huyitao/paste/...[huge string]'
    at Module.lstatSync (node:fs:1713:25)
    at robustRealpath (/Users/huyitao/gemini-cli/packages/core/src/utils/paths.ts:389:25)
    at resolveToRealPath (/Users/huyitao/gemini-cli/packages/core/src/utils/paths.ts:372:10)
    at checkPermissions (/Users/huyitao/gemini-cli/packages/cli/src/ui/hooks/atCommandProcessor.ts:191:28)
RAW_BUFFERClick to expand / collapse

Problem

When pasting a large block of text (e.g., a Python stack trace or a long log file) directly into the interactive CLI prompt, the CLI crashes with an ENAMETOOLONG error.

The root cause is that the input parser (parseAllAtCommands in packages/cli/src/ui/hooks/atCommandProcessor.ts) identifies strings starting with @ as potential file paths and passes them to resolveToRealPath (in packages/core/src/utils/paths.ts). resolveToRealPath calls fs.lstatSync on the entire string without validating its length. If the string is longer than the operating system's maximum path length (e.g., 1024 characters on macOS), Node.js throws Error: ENAMETOOLONG.

Because this occurs during the prompt processing phase and is not caught, it leads to an unhandled promise rejection and a crash.

Expected Behavior

  1. The CLI should not crash when long strings are pasted.
  2. The path resolution logic should have a maximum length check before calling file system APIs.
  3. Errors like ENAMETOOLONG should be caught gracefully, and the string should be treated as literal text if it cannot be resolved as a path.

Environment & Info

  • OS: macOS
  • Terminal: Ghostty 1.3.1
  • Node Version: v24.15.0
  • CLI Version: @google/gemini-cli 0.40.1

Crash Log Fragment:

CRITICAL: Unhandled Promise Rejection!
Reason: Error: ENAMETOOLONG: name too long, lstat '/Users/huyitao/paste/...[huge string]'
    at Module.lstatSync (node:fs:1713:25)
    at robustRealpath (/Users/huyitao/gemini-cli/packages/core/src/utils/paths.ts:389:25)
    at resolveToRealPath (/Users/huyitao/gemini-cli/packages/core/src/utils/paths.ts:372:10)
    at checkPermissions (/Users/huyitao/gemini-cli/packages/cli/src/ui/hooks/atCommandProcessor.ts:191:28)

Additional Context

This bug was discovered when a user pasted a multi-thousand line Tkinter error log into the prompt.

extent analysis

TL;DR

To fix the CLI crash, add a maximum length check before calling fs.lstatSync in resolveToRealPath to prevent ENAMETOOLONG errors.

Guidance

  • Identify the maximum allowed path length for the operating system (e.g., 1024 characters on macOS) and add a check in resolveToRealPath to ensure the input string does not exceed this length.
  • Modify parseAllAtCommands to handle strings starting with @ as potential literal text if they exceed the maximum path length or cannot be resolved as a path.
  • Catch and handle ENAMETOOLONG errors in resolveToRealPath to prevent unhandled promise rejections and provide a graceful fallback.
  • Consider adding input validation and sanitization in parseAllAtCommands to prevent similar issues with other types of input.

Example

// In resolveToRealPath (packages/core/src/utils/paths.ts)
const maxPathLength = 1024; // Adjust according to the operating system
if (inputString.length > maxPathLength) {
  // Handle as literal text or throw a custom error
  throw new Error(`Input string exceeds maximum path length: ${inputString}`);
}

Notes

This fix assumes that the ENAMETOOLONG error is the primary cause of the crash. Additional logging or debugging may be necessary to ensure that other issues are not contributing to the problem.

Recommendation

Apply the workaround by adding a maximum length check in resolveToRealPath to prevent ENAMETOOLONG errors, as this is a targeted fix for the identified root cause.

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

gemini-cli - 💡(How to fix) Fix [Bug] CLI crashes with ENAMETOOLONG when pasting long strings into prompt [3 comments, 2 participants]