diff --git a/src/add/add.ts b/src/add/add.ts index 9208fdc..40c64d7 100644 --- a/src/add/add.ts +++ b/src/add/add.ts @@ -86,7 +86,6 @@ export async function runAdd(options: AddOptions): Promise { const proceed = await warnAboutCDNPricingLimitations() if (!proceed) { cancel('Add cancelled') - process.exitCode = 1 throw new Error('CDN pricing limitations warning cancelled') } } @@ -101,7 +100,7 @@ export async function runAdd(options: AddOptions): Promise { if (!pathValidation.exists || !pathValidation.stats) { spinner.stop(`${pc.red('✗')} ${pathValidation.error}`) cancel('Add cancelled') - process.exit(1) + throw new Error(pathValidation.error) } const pathStat = pathValidation.stats @@ -247,6 +246,6 @@ export async function runAdd(options: AddOptions): Promise { } cancel('Add failed') - process.exit(1) + throw error } } diff --git a/src/commands/add.ts b/src/commands/add.ts index 4c58194..91e546e 100644 --- a/src/commands/add.ts +++ b/src/commands/add.ts @@ -30,8 +30,7 @@ export const addCommand = new Command('add') } await runAdd(addOptions) - } catch (error) { - console.error('Add failed:', error instanceof Error ? error.message : error) + } catch { process.exit(1) } }) diff --git a/src/test/unit/add.test.ts b/src/test/unit/add.test.ts index d40553b..8edfe5c 100644 --- a/src/test/unit/add.test.ts +++ b/src/test/unit/add.test.ts @@ -233,41 +233,35 @@ describe('Add Command', () => { }) it('should reject when file does not exist', async () => { - const mockExit = vi.spyOn(process, 'exit').mockImplementation(() => { - throw new Error('process.exit called') - }) + const mockExit = vi.spyOn(process, 'exit') await expect( runAdd({ filePath: '/non/existent/file.txt', privateKey: 'test-key', }) - ).rejects.toThrow('process.exit called') + ).rejects.toThrow('Path not found') - expect(mockExit).toHaveBeenCalledWith(1) + expect(mockExit).not.toHaveBeenCalled() mockExit.mockRestore() }) it('should reject when private key is missing', async () => { - const mockExit = vi.spyOn(process, 'exit').mockImplementation(() => { - throw new Error('process.exit called') - }) + const mockExit = vi.spyOn(process, 'exit') await expect( runAdd({ filePath: testFile, // No private key }) - ).rejects.toThrow('process.exit called') + ).rejects.toThrow() - expect(mockExit).toHaveBeenCalledWith(1) + expect(mockExit).not.toHaveBeenCalled() mockExit.mockRestore() }) it('should reject --bare flag with directories', async () => { - const mockExit = vi.spyOn(process, 'exit').mockImplementation(() => { - throw new Error('process.exit called') - }) + const mockExit = vi.spyOn(process, 'exit') await expect( runAdd({ @@ -275,9 +269,9 @@ describe('Add Command', () => { privateKey: 'test-key', bare: true, // --bare flag should not work with directories }) - ).rejects.toThrow('process.exit called') + ).rejects.toThrow('--bare flag is not supported for directories') - expect(mockExit).toHaveBeenCalledWith(1) + expect(mockExit).not.toHaveBeenCalled() mockExit.mockRestore() }) })