Aller au contenu principal

safeExecute()

safeExecute(cmd): Result<void, Error>

Executes a command safely, catching any error and returning a zygos Result instead of throwing.

DEPRECATED

Use Result.fromThrowable from @zygos/result/result instead.

import { Result } from "@zygos/result/result";

const safeCmd = Result.fromThrowable(riskyCommand, (e) =>
e instanceof Error ? e : new Error(String(e)),
);
const result = safeCmd();

Parameters

cmd: Command

The command to execute


Returns: Result<void, Error>

Ok(void) on success, Err(Error) on failure


See Also

Full explanation, examples and live demo


Since

2.4.0