Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions src/features/ignore/claudecode-ignore.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,26 @@ describe("ClaudecodeIgnore", () => {
// existing shared settings.json untouched on disk.
expect(claudecodeIgnore.getRelativeFilePath()).toBe("settings.local.json");
});

it("should throw a formatted error when the existing settings.json is malformed", async () => {
const claudeDir = join(testDir, ".claude");
await ensureDir(claudeDir);
await writeFileContent(join(claudeDir, "settings.json"), "{ not valid json");

const rulesyncIgnore = new RulesyncIgnore({
relativeDirPath: RULESYNC_RELATIVE_DIR_PATH,
relativeFilePath: RULESYNC_AIIGNORE_RELATIVE_FILE_PATH,
fileContent: "*.log",
});

await expect(
ClaudecodeIgnore.fromRulesyncIgnore({
outputRoot: testDir,
rulesyncIgnore,
options: { fileMode: "shared" },
}),
).rejects.toThrow(/Failed to parse existing Claude settings at .*settings\.json/);
});
});

describe("isDeletable", () => {
Expand Down
11 changes: 10 additions & 1 deletion src/features/ignore/claudecode-ignore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
} from "../../constants/claudecode-paths.js";
import type { ClaudeSettingsJson } from "../../types/claude-settings.js";
import { FeatureOptions } from "../../types/features.js";
import { formatError } from "../../utils/error.js";
import { fileExists, readFileContent } from "../../utils/file.js";
import {
applyIgnoreReadDenies,
Expand Down Expand Up @@ -143,7 +144,15 @@ export class ClaudecodeIgnore extends ToolIgnore {
const filePath = join(outputRoot, paths.relativeDirPath, paths.relativeFilePath);
const exists = await fileExists(filePath);
const existingFileContent = exists ? await readFileContent(filePath) : "{}";
const existingJsonValue: ClaudeSettingsJson = JSON.parse(existingFileContent);
let existingJsonValue: ClaudeSettingsJson;
try {
existingJsonValue = JSON.parse(existingFileContent);
} catch (error) {
throw new Error(
`Failed to parse existing Claude settings at ${filePath}: ${formatError(error)}`,
{ cause: error },
);
}

// The gateway owns the `permissions.deny` merge shared with the permissions
// feature; here we only state the intent (deny these Read patterns).
Expand Down
Loading