Skip to content

Commit

Permalink
clean panic
Browse files Browse the repository at this point in the history
  • Loading branch information
hazae41 committed May 23, 2023
1 parent 60a7072 commit 7eb4b6c
Showing 1 changed file with 0 additions and 27 deletions.
27 changes: 0 additions & 27 deletions src/mods/result/panic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,30 +7,3 @@ export class Panic extends Error {
}

}

export namespace Panic {

/**
* Throw `error` if `Panic`, return `error` otherwise
* @param error
* @returns error if not `Panic`
* @throws error if `Panic`
*/
export function rethrow<T>(error: T): Exclude<T, Panic> {
if (error instanceof Panic)
throw error
return error as Exclude<T, Panic>
}

/**
* Convert error to `Panic` if not already
* @param error
* @returns `error` if `Panic`, `Panic.from(error)` otherwise
*/
export function castOrFrom(error: unknown) {
if (error instanceof Panic)
return error
return Panic.from(error)
}

}

0 comments on commit 7eb4b6c

Please sign in to comment.