mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-05 20:34:18 +01:00
20 lines
472 B
TypeScript
20 lines
472 B
TypeScript
export function catchThrownError(action: () => void): Error {
|
|
try {
|
|
action()
|
|
} catch (error) {
|
|
if (error instanceof Error) return error
|
|
throw error
|
|
}
|
|
throw new Error('Expected the action to throw')
|
|
}
|
|
|
|
export async function catchRejectedError(promise: Promise<unknown>): Promise<Error> {
|
|
try {
|
|
await promise
|
|
} catch (error) {
|
|
if (error instanceof Error) return error
|
|
throw error
|
|
}
|
|
throw new Error('Expected the promise to reject')
|
|
}
|