Skip to content

fix(core): silently skip GEMINI.md paths that are directories (EISDIR)#22852

Closed
shathwik30 wants to merge 2 commits intogoogle-gemini:mainfrom
shathwik30:fix/eisdir-gemini-md-directory
Closed

fix(core): silently skip GEMINI.md paths that are directories (EISDIR)#22852
shathwik30 wants to merge 2 commits intogoogle-gemini:mainfrom
shathwik30:fix/eisdir-gemini-md-directory

Conversation

@shathwik30
Copy link
Copy Markdown

Summary

Fixes #16282

When a directory named GEMINI.md exists anywhere in the project tree, fs.access() succeeds (directories are readable), so the path gets added to the memory discovery list. The subsequent fs.readFile() call then throws EISDIR, which was previously caught and emitted as a logger.warn() — surfacing a confusing warning for a completely valid project structure.

Root cause

In readGeminiMdFiles, the catch block treated all read errors equally, forwarding them to logger.warn. An EISDIR error is not an unexpected failure — it simply means a directory exists where a file was expected, and the right action is to skip it silently.

Fix

Applied the EAFP pattern inside readGeminiMdFiles (packages/core/src/utils/memoryDiscovery.ts): detect the EISDIR error code and demote it to a debugLogger.debug call, silently returning null content for that path. All other error types continue to produce a logger.warn as before.

const isEISDIR =
  typeof error === 'object' &&
  error !== null &&
  'code' in error &&
  (error as { code: string }).code === 'EISDIR';

if (isEISDIR) {
  // A directory exists where a GEMINI.md file is expected — skip silently.
  debugLogger.debug('[DEBUG] [MemoryDiscovery] Skipping directory at GEMINI.md path:', filePath);
} else {
  // warn for genuine unexpected read errors
  ...
}

Test plan

  • Added should silently skip a GEMINI.md path that is a directory (EISDIR) unit test — creates a GEMINI.md/ directory in the workspace and asserts that loadServerHierarchicalMemory returns empty content without throwing or warning
  • All 38 existing tests in memoryDiscovery.test.ts pass
  • Pre-commit hooks (prettier + eslint) pass

🤖 Generated with Claude Code

When a directory named GEMINI.md exists in the project tree, fs.access()
succeeds (directories are readable), so the path is added to the discovery
list. The subsequent fs.readFile() then throws EISDIR, which was previously
caught and emitted as a logger.warn(), surfacing a noisy warning for a
completely valid project structure.

Apply the EAFP pattern: detect the EISDIR error code in readGeminiMdFiles
and demote it to a debug-level log, silently returning null content for
that path. All other errors continue to be warned as before.

Add a unit test that creates a GEMINI.md directory alongside real files
and asserts that loadServerHierarchicalMemory returns empty content
without throwing.

Fixes google-gemini#16282

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@shathwik30 shathwik30 requested a review from a team as a code owner March 17, 2026 20:02
@google-cla
Copy link
Copy Markdown

google-cla Bot commented Mar 17, 2026

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@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 refines the memory discovery process by introducing robust error handling for GEMINI.md file paths. Previously, if a directory was named GEMINI.md, the system would issue a warning, which was misleading for a valid project setup. The changes ensure that such directory paths are now silently skipped, improving the user experience by eliminating confusing warnings and making the system more resilient to diverse project structures.

Highlights

  • Error Handling: Implemented specific error handling for EISDIR (Is Directory) errors when processing GEMINI.md paths, preventing fs.readFile() from throwing confusing warnings when a directory exists instead of a file.
  • Logging: Demoted EISDIR warnings to debugLogger.debug calls, ensuring that valid project structures with GEMINI.md directories do not produce unnecessary warnings.
  • Testing: Added a new unit test to verify that the system silently skips GEMINI.md paths that are directories and returns empty content without errors.
Changelog
  • packages/core/src/utils/memoryDiscovery.test.ts
    • Added a new test case should silently skip a GEMINI.md path that is a directory (EISDIR) to validate the new error handling.
  • packages/core/src/utils/memoryDiscovery.ts
    • Modified the readGeminiMdFiles function to specifically check for EISDIR error codes.
    • Changed EISDIR errors to be logged at the debug level instead of a warning, and return null content.
    • Ensured other types of read errors still produce a logger.warn.
Activity
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.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

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 effectively addresses a bug where a directory named GEMINI.md would cause an EISDIR error and generate a confusing warning. The fix correctly identifies this specific error code and handles it gracefully by skipping the warning. The addition of a dedicated unit test is a great way to ensure this fix is robust and prevents future regressions. The suggestion to improve the type safety of the error checking logic is valid and has been retained.

Comment thread packages/core/src/utils/memoryDiscovery.ts Outdated
@shathwik30
Copy link
Copy Markdown
Author

I have read the CLA Document and I hereby sign the CLA

Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
@gemini-cli gemini-cli Bot added priority/p2 Important but can be addressed in a future release. area/core Issues related to User Interface, OS Support, Core Functionality help wanted We will accept PRs from all issues marked as "help wanted". Thanks for your support! labels Mar 17, 2026
@cocosheng-g
Copy link
Copy Markdown
Contributor

Hi @shathwik30, this PR is being closed due to test failures and 23 days of inactivity. To keep the review queue manageable, we are closing stale blocked PRs. Please feel free to re-open this PR or open a new one once the issues are resolved! Thank you for your contribution.

@cocosheng-g cocosheng-g closed this Apr 9, 2026
martin-hsu-test added a commit to martin-hsu-test/gemini-cli that referenced this pull request Apr 19, 2026
When a directory named GEMINI.md exists in the workspace tree, the memory
discovery process previously logged a confusing 'Could not read GEMINI.md'
warning because fs.readFile throws EISDIR on directories. Directories with
that name are valid in some project structures and should simply be ignored.

Detect EISDIR specifically in the readGeminiMdFiles catch block and skip
silently with a debug log, while preserving the warning behaviour for
genuinely unexpected read errors.

Adds two tests:
- a direct readGeminiMdFiles test asserting null content (no throw) when
  given a directory path
- an end-to-end loadServerHierarchicalMemory test asserting empty memory
  when a GEMINI.md directory is present in the workspace

Fixes google-gemini#16282

Supersedes google-gemini#22852 (closed due to test failures and inactivity); the
production fix here uses the same NodeJS.ErrnoException type guard that
gemini-code-assist suggested on that PR, with fresh tests written from
scratch against the current code.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/core Issues related to User Interface, OS Support, Core Functionality help wanted We will accept PRs from all issues marked as "help wanted". Thanks for your support! priority/p2 Important but can be addressed in a future release.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Core] Handle EISDIR error when GEMINI.md is a directory during memory discovery

2 participants