({
args,
env,
timeoutMs,
signal,
}: OpCliInvocation)
| 46 | * CLI's human-readable diagnostics, so a non-zero exit reports stderr when |
| 47 | * present (falling back to the spawn error, e.g. `spawn op ENOENT`). */ |
| 48 | export const opCliExec = ({ |
| 49 | args, |
| 50 | env, |
| 51 | timeoutMs, |
| 52 | signal, |
| 53 | }: OpCliInvocation): Promise<OpCliResult> => |
| 54 | new Promise((resolve) => { |
| 55 | execFile( |
| 56 | "op", |
| 57 | args, |
| 58 | { |
| 59 | env: env as NodeJS.ProcessEnv, |
| 60 | timeout: timeoutMs, |
| 61 | signal, |
| 62 | maxBuffer: 16 * 1024 * 1024, |
| 63 | }, |
| 64 | (error, stdout, stderr) => { |
| 65 | if (error === null) { |
| 66 | resolve({ ok: true, stdout }); |
| 67 | return; |
| 68 | } |
| 69 | const stderrText = stderr.trim(); |
| 70 | resolve({ |
| 71 | ok: false, |
| 72 | timedOut: isExecFileError(error) && error.killed === true, |
| 73 | message: stderrText.length > 0 ? stderrText : describeSpawnError(error), |
| 74 | }); |
| 75 | }, |
| 76 | ); |
| 77 | }); |
no test coverage detected