-
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.
Fix directory creation in fs init in beekeeper
- Loading branch information
Showing
3 changed files
with
42 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,32 @@ | ||
import { BeekeeperError } from "../errors.js"; | ||
|
||
// TODO: Check for errno on Windows | ||
const stringifyError = (error: unknown): string => { | ||
if (error instanceof Error) | ||
return error.message; | ||
|
||
const name = error && typeof error === "object" && "name" in error ? error.name : undefined; | ||
|
||
if (name === "ErrnoError" && "errno" in (error as object)) { | ||
const errno = (error as any).errno as number; | ||
return `ErrnoError: #${errno}`; | ||
} | ||
|
||
return "Unknown error" + (name ? `: ${name}` : ""); | ||
}; | ||
|
||
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}`); | ||
throw new BeekeeperError(`Error during Wasm call: ${stringifyError(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}`); | ||
throw new BeekeeperError(`Error during Wasm call: ${stringifyError(error)}`); | ||
} | ||
}; |