-
Notifications
You must be signed in to change notification settings - Fork 108
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add wasmSafeCall utility method to beekeeper TS to make errors easier…
… to read
- Loading branch information
Showing
6 changed files
with
56 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { BeekeeperError } from "../errors.js"; | ||
|
||
export const safeWasmCall = <T extends () => any>(fn: T): ReturnType<T> => { | ||
try { | ||
return fn() | ||
} catch (error) { | ||
throw new BeekeeperError(`Error during Wasm call: ${error instanceof Error ? error.message : error}`); | ||
} | ||
}; | ||
|
||
export const safeAsyncWasmCall = async <T extends () => any>(fn: T): Promise<ReturnType<T>> => { | ||
try { | ||
return await fn(); | ||
} catch (error) { | ||
throw new BeekeeperError(`Error during Wasm call: ${error instanceof Error ? error.message : error}`); | ||
} | ||
}; |