Skip to content

Commit 7f606e8

Browse files
committed
refactor: validate CLAUDE_CONFIG_DIR before projects subfolder
- 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)
1 parent 9f11ed8 commit 7f606e8

1 file changed

Lines changed: 13 additions & 4 deletions

File tree

‎src/data-loader.ts‎

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,19 @@ export function getDefaultClaudePath(): string {
3535
return DEFAULT_CLAUDE_CODE_PATH;
3636
}
3737

38+
// First validate that the CLAUDE_CONFIG_DIR itself exists and is a directory
39+
if (!isDirectorySync(envClaudeCodePath)) {
40+
throw new Error(
41+
`CLAUDE_CONFIG_DIR path is not a valid directory: ${envClaudeCodePath}.
42+
Please set CLAUDE_CONFIG_DIR to a valid directory path, or ensure ${DEFAULT_CLAUDE_CODE_PATH} exists.
43+
`.trim(),
44+
);
45+
}
46+
3847
const claudeCodeProjectsPath = path.join(envClaudeCodePath, 'projects');
3948
if (!isDirectorySync(claudeCodeProjectsPath)) {
4049
throw new Error(
41-
` Claude data directory does not exist: ${claudeCodeProjectsPath}.
50+
`Claude data directory does not exist: ${claudeCodeProjectsPath}.
4251
Please set CLAUDE_CONFIG_DIR to a valid path, or ensure ${DEFAULT_CLAUDE_CODE_PATH} exists.
4352
`.trim(),
4453
);
@@ -1093,20 +1102,20 @@ if (import.meta.vitest != null) {
10931102

10941103
vi.stubEnv('CLAUDE_CONFIG_DIR', nonExistentPath);
10951104

1096-
expect(() => getDefaultClaudePath()).toThrow(/Claude data directory does not exist/);
1105+
expect(() => getDefaultClaudePath()).toThrow(/CLAUDE_CONFIG_DIR path is not a valid directory/);
10971106
});
10981107

10991108
it('throws an error when CLAUDE_CONFIG_DIR does not exist', () => {
11001109
vi.stubEnv('CLAUDE_CONFIG_DIR', '/nonexistent/path/that/does/not/exist');
11011110

1102-
expect(() => getDefaultClaudePath()).toThrow(/Claude data directory does not exist/);
1111+
expect(() => getDefaultClaudePath()).toThrow(/CLAUDE_CONFIG_DIR path is not a valid directory/);
11031112
});
11041113

11051114
it('throws an error when default path does not exist', () => {
11061115
// Set to a non-existent path
11071116
vi.stubEnv('CLAUDE_CONFIG_DIR', '/nonexistent/path/.claude');
11081117

1109-
expect(() => getDefaultClaudePath()).toThrow(/Claude data directory does not exist/);
1118+
expect(() => getDefaultClaudePath()).toThrow(/CLAUDE_CONFIG_DIR path is not a valid directory/);
11101119
});
11111120
});
11121121

0 commit comments

Comments
 (0)