🌋 Adds exception to error type to help debugging

This commit is contained in:
Rune Harlyk
2024-02-23 00:57:58 +01:00
parent 1b2d583230
commit 1f8d753dd7
2 changed files with 15 additions and 9 deletions
+11 -5
View File
@@ -1,14 +1,20 @@
export class Err<T> {
export class Err<T, U> {
#inner: T
#exception?: U
constructor(inner: T) {
constructor(inner: T, exception?: U) {
this.#inner = inner
this.#exception = exception
}
get inner(): T {
return this.#inner
}
get exception(): U | undefined {
return this.#exception;
}
/**
* Type guard for `Ok`
* @returns `true` if `Ok`; `false` if `Err`
@@ -21,7 +27,7 @@ export class Err<T> {
* Type guard for `Err`
* @returns `true` if `Err`; `false` if `Ok`
*/
isErr(): this is Err<T> {
isErr(): this is Err<T, U> {
return true
}
@@ -30,7 +36,7 @@ export class Err<T> {
* @param inner
* @returns `Err(inner)`
*/
static new<E>(inner: E): Err<E> {
return new Err<E>(inner)
static new<E, F>(inner: E, exception: F): Err<E, F> {
return new Err<E, F>(inner, exception)
}
}