mirror of
https://github.com/getpaseo/paseo.git
synced 2026-07-29 12:01:31 +00:00
What changed: - Added a shared utility `getErrorMessage(error: unknown)` in `packages/cli/src/utils/errors.ts`. - Refactored `packages/cli/src/commands/daemon/start.ts` to use `getErrorMessage` and a local `exitWithError` helper instead of repeating inline error-message extraction + exit logic in each catch block. - Added `packages/cli/tests/19-errors-utils.test.ts` to lock utility behavior for Error and non-Error throw values. Reasoning: - `runStart` had repeated branching (`err instanceof Error ? err.message : String(err)`) across multiple catch sites. - Centralizing this keeps behavior stable while reducing duplication and cognitive overhead, aligned with the refactor skill guidance to simplify structure without changing user-visible behavior. Verification: - Ran `npx tsx packages/cli/tests/18-local-daemon-utils.test.ts` (pass). - Ran `npx tsx packages/cli/tests/19-errors-utils.test.ts` (pass). - Ran `npm run -w @getpaseo/cli typecheck` (pass). Notes for next agent: - Existing `scripts/codex-refactor-loop.sh` was already modified before this change and is intentionally not included. - `packages/cli/tests/03-daemon.test.ts` currently failed in this environment because Test 3 expected daemon status failure, but command exited successfully (likely environment state dependent). This refactor does not touch that path; worth deflakifying or isolating in a follow-up.
23 lines
670 B
TypeScript
23 lines
670 B
TypeScript
#!/usr/bin/env npx tsx
|
|
|
|
import assert from 'node:assert'
|
|
import { getErrorMessage } from '../src/utils/errors.js'
|
|
|
|
console.log('=== Error Utils ===\n')
|
|
|
|
{
|
|
console.log('Test 1: returns Error.message for Error instances')
|
|
assert.strictEqual(getErrorMessage(new Error('boom')), 'boom')
|
|
console.log('✓ returns Error.message\n')
|
|
}
|
|
|
|
{
|
|
console.log('Test 2: stringifies non-Error values')
|
|
assert.strictEqual(getErrorMessage('plain string'), 'plain string')
|
|
assert.strictEqual(getErrorMessage(42), '42')
|
|
assert.strictEqual(getErrorMessage(null), 'null')
|
|
console.log('✓ stringifies non-Error values\n')
|
|
}
|
|
|
|
console.log('=== All error utility tests passed ===')
|