import { toError } from './errors.js'; type Fn = (...args: Args) => Result; type Result = [value: T, error: undefined] | [value: undefined, error: Error]; /** * Execute a function and return a result tuple * * This is a helper function to make it easier to handle errors without the extra nesting of try/catch */ export const exec = async >( fn: Fn, ...args: Args ): Promise>> => { try { const result = await fn(...args); return [result, undefined]; } catch (error) { return [undefined, toError(error)]; } };