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
13 changes: 8 additions & 5 deletions src/tui/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -690,12 +690,15 @@ export const App: React.FC = () => {
color: 'green'
});
}
} catch {
setFlashMessage({
text: '✗ Install failed',
color: 'red'
} catch (err) {
setFlashMessage(null);
setFlowNotice({
title: 'Install Failed',
message: err instanceof Error ? err.message : String(err),
color: 'red',
continueScreen: 'install'
});
setScreen('install');
setScreen('flowNotice');
}
setConfirmDialog(null);
}
Expand Down
23 changes: 7 additions & 16 deletions src/utils/__tests__/claude-settings.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -496,25 +496,16 @@ describe('backup and error handling behavior', () => {
}
});

it('installStatusLine should warn and recover when existing settings are invalid', async () => {
it('installStatusLine should abort without touching existing settings that cannot be parsed', async () => {
writeRawClaudeSettings('{ invalid json');
const consoleErrorSpy = vi.spyOn(console, 'error').mockImplementation(() => undefined);
try {
await installStatusLine({ commandMode: 'auto-npx' });
const settingsPath = getClaudeSettingsPath();

const settingsPath = getClaudeSettingsPath();
const installed = JSON.parse(fs.readFileSync(settingsPath, 'utf-8')) as { statusLine?: { command?: string; padding?: number } };
expect(installed.statusLine?.command).toBe(buildStatusLineCommand('auto-npx'));
expect(installed.statusLine?.padding).toBe(0);
expect(fs.existsSync(`${settingsPath}.orig`)).toBe(true);
expect(fs.readFileSync(`${settingsPath}.orig`, 'utf-8')).toBe('{ invalid json');
const installPromise = installStatusLine({ commandMode: 'auto-npx' });
await expect(installPromise).rejects.toThrow(settingsPath);

expect(consoleErrorSpy).toHaveBeenCalledWith(
`Warning: Could not read existing Claude settings. A backup exists at ${settingsPath}.orig.`
);
} finally {
consoleErrorSpy.mockRestore();
}
expect(fs.readFileSync(settingsPath, 'utf-8')).toBe('{ invalid json');
expect(fs.existsSync(`${settingsPath}.bak`)).toBe(false);
expect(fs.existsSync(`${settingsPath}.orig`)).toBe(false);
});

it('uninstallStatusLine should warn and return without modifying invalid settings', async () => {
Expand Down
13 changes: 8 additions & 5 deletions src/utils/claude-settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -405,15 +405,18 @@ export async function installStatusLine({
}: InstallStatusLineOptions): Promise<void> {
let settings: ClaudeSettings;

const backupPath = await backupClaudeSettings('.orig');
// A missing settings file loads as {}; any error here means the file exists
// but could not be read or parsed. Abort rather than overwrite it with only
// our statusLine, which would discard the user's other Claude Code settings.
try {
settings = await loadClaudeSettings({ logErrors: false });
} catch {
const fallbackBackupPath = `${getClaudeSettingsPath()}.orig`;
console.error(`Warning: Could not read existing Claude settings. A backup exists at ${backupPath ?? fallbackBackupPath}.`);
settings = {};
} catch (error) {
const reason = error instanceof Error ? error.message : String(error);
throw new Error(`Could not read existing Claude settings at ${getClaudeSettingsPath()} (${reason}). The file was left unchanged; fix or remove it, then install again.`, { cause: error });
}

await backupClaudeSettings('.orig');

// Update settings with our status line (confirmation already handled in TUI)
const existingRefreshInterval = settings.statusLine?.refreshInterval;
settings.statusLine = {
Expand Down
Loading