-
-
Notifications
You must be signed in to change notification settings - Fork 317
fix: improve Claude data directory validation #95
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
Warning Rate limit exceeded@ryoppippi has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 16 minutes and 47 seconds before requesting another review. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. 📥 CommitsReviewing files that changed from the base of the PR and between 293462d54f709c284880b8896dc423e8fa60e30d and 7f606e8. 📒 Files selected for processing (1)
WalkthroughThe logic of the Changes
Sequence Diagram(s)sequenceDiagram
participant Caller
participant Env
participant FS
Caller->>Env: Read CLAUDE_CONFIG_DIR
alt CLAUDE_CONFIG_DIR unset or empty
Caller->>FS: Check ~/.claude/projects exists
alt projects exists
FS-->>Caller: Return ~/.claude
else projects missing
FS-->>Caller: Throw error
end
else CLAUDE_CONFIG_DIR is set
Caller->>FS: Check $CLAUDE_CONFIG_DIR/projects exists
alt projects exists
FS-->>Caller: Return $CLAUDE_CONFIG_DIR
else projects missing
FS-->>Caller: Throw error referencing projects path
end
end
Assessment against linked issues
Assessment against linked issues: Out-of-scope changesNo out-of-scope changes found. Possibly related PRs
Poem
✨ Finishing Touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Summary of Changes
Hello @nakatanakatana, 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 an issue by refining how the Claude data directory is validated. The core change involves enforcing the presence of a 'projects' subdirectory within the configured data path, making the path resolution more explicit and robust. This ensures that the application relies on a correctly structured data directory.
Highlights
- Improved Data Directory Validation: The
getDefaultClaudePathfunction now includes a more robust validation check. It ensures that the directory specified byCLAUDE_CONFIG_DIR(or the default~/.claudepath) contains a mandatoryprojectssubdirectory. If this subdirectory is not found, an error is now explicitly thrown, providing clearer feedback to the user. - Enhanced Test Coverage: New test cases have been added to
data-loader.test.tsto specifically verify the improved validation logic. These tests confirm thatgetDefaultClaudePathcorrectly throws an error when theCLAUDE_CONFIG_DIRpoints to a location that lacks the expectedprojectssubdirectory. Existing test fixtures were also updated to align with the new expectation of aprojectssubdirectory.
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 in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.
| 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 issue 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 is currently in preview and 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 to provide feedback.
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
-
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. ↩
There was a problem hiding this 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 addresses issue #90 by improving the validation logic for the CLAUDE_CONFIG_DIR environment variable. The getDefaultClaudePath function now correctly checks for the existence of the projects subdirectory within the specified path when the environment variable is set, aligning with the expected data structure. Tests have been updated and a new test added to cover this specific validation case. The changes are well-implemented and improve the robustness of the data loading process.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
🔭 Outside diff range comments (1)
src/data-loader.ts (1)
34-41: Validate the fallback path as well
getDefaultClaudePathnow guaranteesprojects/exists only whenCLAUDE_CONFIG_DIRis set.
When the variable is not set we blindly return~/.claudeeven if that directory (and itsprojectssub-dir) is missing.
load*functions later on use this path ascwdfortinyglobby; if it does not existtinyglobbywill throw, causing a less helpful stack trace.- return DEFAULT_CLAUDE_CODE_PATH; + const defaultProjectsPath = path.join(DEFAULT_CLAUDE_CODE_PATH, 'projects'); + if (!isDirectorySync(defaultProjectsPath)) { + throw new Error( + `Claude data directory does not exist: ${defaultProjectsPath}. ` + + `Create it or set CLAUDE_CONFIG_DIR.` + ); + } + return DEFAULT_CLAUDE_CODE_PATH;
🧹 Nitpick comments (2)
src/data-loader.ts (1)
37-38: Super-fluous leading whitespace in error messageThe template literal starts with a space, producing
" Claude data directory…".
Trimming later removes line-breaks but keeps the leading space.- ` Claude data directory does not exist: ${claudeCodeProjectsPath}. + `Claude data directory does not exist: ${claudeCodeProjectsPath}.src/data-loader.test.ts (1)
103-110: Fix typo in test descriptionMinor typo: “dose” → “does”.
-test('throws an error when CLAUDE_CONFIG_DIR dose not have a "projects" directory', async () => { +test('throws an error when CLAUDE_CONFIG_DIR does not have a "projects" directory', async () => {
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📥 Commits
Reviewing files that changed from the base of the PR and between 3506c38 and da6d10da78d580f49021c14d44043a074087a1c8.
📒 Files selected for processing (2)
src/data-loader.test.ts(2 hunks)src/data-loader.ts(1 hunks)
🧰 Additional context used
🪛 ESLint
src/data-loader.test.ts
[error] 98-98: Unsafe member access .env on an error typed value.
(ts/no-unsafe-member-access)
[error] 98-98: Unsafe member access .path on an error typed value.
(ts/no-unsafe-member-access)
[error] 100-100: Unsafe call of a(n) error type typed value.
(ts/no-unsafe-call)
[error] 100-100: Unsafe call of a(n) error type typed value.
(ts/no-unsafe-call)
[error] 100-100: Unsafe member access .toBe on an error typed value.
(ts/no-unsafe-member-access)
[error] 100-100: Unsafe member access .path on an error typed value.
(ts/no-unsafe-member-access)
[error] 103-103: Unsafe call of a(n) error type typed value.
(ts/no-unsafe-call)
[error] 104-106: Unsafe assignment of an error typed value.
(ts/no-unsafe-assignment)
[error] 104-104: Unsafe call of a(n) error type typed value.
(ts/no-unsafe-call)
[error] 107-107: Unsafe assignment of an error typed value.
(ts/no-unsafe-assignment)
[error] 107-107: Unsafe member access .env on an error typed value.
(ts/no-unsafe-member-access)
[error] 107-107: Unsafe member access .path on an error typed value.
(ts/no-unsafe-member-access)
[error] 109-109: Unsafe call of a(n) error type typed value.
(ts/no-unsafe-call)
[error] 109-109: Unsafe call of a(n) error type typed value.
(ts/no-unsafe-call)
[error] 109-109: Unsafe member access .toThrow on an error typed value.
(ts/no-unsafe-member-access)
src/data-loader.ts
[error] 29-29: Unsafe assignment of an error typed value.
(ts/no-unsafe-assignment)
[error] 29-29: Unsafe call of a(n) error type typed value.
(ts/no-unsafe-call)
[error] 29-29: Unsafe member access .env on an error typed value.
(ts/no-unsafe-member-access)
[error] 31-31: Unsafe return of a value of type error.
(ts/no-unsafe-return)
[error] 34-34: Unsafe assignment of an error typed value.
(ts/no-unsafe-assignment)
[error] 34-34: Unsafe call of a(n) error type typed value.
(ts/no-unsafe-call)
[error] 34-34: Unsafe member access .join on an error typed value.
(ts/no-unsafe-member-access)
[error] 35-35: Unexpected any value in conditional. An explicit comparison or type conversion is required.
(ts/strict-boolean-expressions)
[error] 35-35: Unsafe call of a(n) error type typed value.
(ts/no-unsafe-call)
⏰ Context from checks skipped due to timeout of 90000ms (1)
- GitHub Check: Socket Security: Pull Request Alerts
🔇 Additional comments (2)
src/data-loader.test.ts (2)
74-82: Fixture update LGTMSwitching the fixture root to contain a
projectsdirectory mirrors the new validation logic and keeps the test meaningful.
93-101: Consistent fixture trimmingSame positive change as above – no action needed.
|
hi. please resolve conflicts! |
da6d10d to
293462d
Compare
ryoppippi
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR improves validation for the Claude data directory by ensuring that the required "projects" subdirectory exists, thereby providing clearer error messages when it is missing. In addition, the test coverage has been updated to verify this stricter validation behavior.
- Improved directory validation by checking for the existence of a "projects" subdirectory.
- Updated test fixtures to reflect the new configuration requirements.
Comments suppressed due to low confidence (2)
src/data-loader.ts:34
- [nitpick] Consider adding a comment explaining why an empty CLAUDE_CONFIG_DIR results in returning DEFAULT_CLAUDE_CODE_PATH. This would improve clarity for future maintainers.
if (envClaudeCodePath === '') {
src/data-loader.ts:1059
- [nitpick] Ensure the test fixture change from 'claude' to 'projects' aligns with the updated validation logic for the directory structure. Additional tests verifying the absence of the 'projects' subdirectory could further enhance coverage.
projects: {},
commit: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
♻️ Duplicate comments (1)
src/data-loader.ts (1)
33-38: Still missing the early check thatCLAUDE_CONFIG_DIRitself is a directoryThe earlier review already pointed this out: if
CLAUDE_CONFIG_DIRpoints to an existing file (or broken symlink), the current logic happily appendsprojectsand only fails on that sub-path, yielding a misleading error.
Fail fast on the base path first and keep the existingprojectscheck.const envClaudeCodePath = process.env.CLAUDE_CONFIG_DIR?.trim() ?? ''; if (envClaudeCodePath === '') { return DEFAULT_CLAUDE_CODE_PATH; } + // Validate that the env path itself exists *and* is a directory + if (!isDirectorySync(envClaudeCodePath)) { + throw new Error( + `CLAUDE_CONFIG_DIR must point to an existing directory: ${envClaudeCodePath}`, + ); + } + const claudeCodeProjectsPath = path.join(envClaudeCodePath, 'projects');
🧹 Nitpick comments (2)
src/data-loader.ts (2)
41-44: Error message formatting nitThere is an unintended leading space and super-fluous newline in the thrown message.
- ` Claude data directory does not exist: ${claudeCodeProjectsPath}. + `Claude data directory does not exist: ${claudeCodeProjectsPath}. Please set CLAUDE_CONFIG_DIR to a valid path, or ensure ${DEFAULT_CLAUDE_CODE_PATH} exists.
33-35: ESLint “unsafe-*” warnings originate from the untypedprocess.envaccessCasting once avoids the cascade of
ts/no-unsafe-*complaints:- const envClaudeCodePath = process.env.CLAUDE_CONFIG_DIR?.trim() ?? ''; + const envClaudeCodePath = (process.env.CLAUDE_CONFIG_DIR ?? '').trim();
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📥 Commits
Reviewing files that changed from the base of the PR and between da6d10da78d580f49021c14d44043a074087a1c8 and 293462d54f709c284880b8896dc423e8fa60e30d.
📒 Files selected for processing (1)
src/data-loader.ts(3 hunks)
🧰 Additional context used
🪛 ESLint
src/data-loader.ts
[error] 33-33: Unsafe assignment of an error typed value.
(ts/no-unsafe-assignment)
[error] 33-33: Unsafe call of a(n) error type typed value.
(ts/no-unsafe-call)
[error] 33-33: Unsafe member access .env on an error typed value.
(ts/no-unsafe-member-access)
[error] 35-35: Unsafe return of a value of type error.
(ts/no-unsafe-return)
[error] 38-38: Unsafe assignment of an error typed value.
(ts/no-unsafe-assignment)
[error] 38-38: Unsafe call of a(n) error type typed value.
(ts/no-unsafe-call)
[error] 38-38: Unsafe member access .join on an error typed value.
(ts/no-unsafe-member-access)
[error] 39-39: Unexpected any value in conditional. An explicit comparison or type conversion is required.
(ts/strict-boolean-expressions)
[error] 39-39: Unsafe call of a(n) error type typed value.
(ts/no-unsafe-call)
1c7e83b to
0a76d21
Compare
- Add validation to check if CLAUDE_CONFIG_DIR itself exists and is a directory before checking the projects subfolder - Provide clearer error message when CLAUDE_CONFIG_DIR is invalid (e.g., file, broken symlink, or non-existent) - This prevents confusing downstream errors and improves user experience with early error detection - Also fix minor formatting issue in error message (remove extra leading space)
0a76d21 to
7f606e8
Compare
fix: improve Claude data directory validation
fix #90
Summary by CodeRabbit
Bug Fixes
Tests