/** * @file Spawn error classification and enhancement. `isSpawnError` is a * type-guard for shaping unknown errors that crossed an `await spawn(...)`. * It checks for the `code` / `errno` / `syscall` properties that Node's * child_process tags onto `ENOENT` / `EACCES` / process-exit failures. * `isSpawnExitError` narrows further, to the failures whose process actually * ran and exited — the ones whose `.code` is the NUMERIC exit status. That * distinction is load-bearing: a spawn fails in two shapes, and a launch * failure carries a string `.code` (`'ENOENT'`) while a non-zero exit carries * a number. Both satisfy `isSpawnError`, so code reading `.code` as a number * after that guard alone is wrong for half its inputs. * `enhanceSpawnError` rewrites the upstream `@npmcli/promise-spawn` "command * failed" placeholder message into something the operator can actually act * on: command + args (truncated at 100 chars), exit code or signal, and the * first stderr line (truncated at 200 chars). The stack is computed lazily on * first access via a per-error WeakMap so non-error paths don't pay the * `stackWithCauses` cost. */ import type { SpawnError } from './types.js'; /** * Enhances spawn error with better context. Converts generic "command failed" * to detailed error with command, exit code, and stderr. * * @example * ;```typescript * try { * await spawn('git', ['status']) * } catch (e) { * throw enhanceSpawnError(e) * } * ``` */ export declare function enhanceSpawnError(error: unknown): unknown; export declare function formatSpawnErrorArgs(args: SpawnError['args']): string; /** * Check if a value is a spawn error with expected error properties. Tests for * common error properties from child process failures. * * @example * try { * await spawn('nonexistent-command') * } catch (e) { * if (isSpawnError(e)) { * console.error(`Spawn failed: ${e.code}`) * } * } * * @param {unknown} value - Value to check. * * @returns {boolean} `true` if the value has spawn error properties */ export declare function isSpawnError(value: unknown): value is SpawnError; /** * Narrow a caught value to a spawn failure whose process actually RAN and then * exited non-zero — the case where `.code` is the numeric exit status. * * `isSpawnError` alone is not enough for that. A spawn fails in two shapes and * they carry different `code` types: * * | failure | `.code` | type | * | ---------------------- | ---------- | -------- | * | process exits non-zero | `3` | `number` | * | command not found | `'ENOENT'` | `string` | * * Both satisfy `isSpawnError`, so reading `.code` as a number after that guard * is wrong for the launch-failure case. Use this predicate when the exit status * is what you want, and {@link isErrnoException} when the launch failure is. * * @example * try { * await spawn('git', ['grep', '-q', needle]) * } catch (e) { * // `git grep` exits 1 for "no match", which is an answer, not a failure. * if (isSpawnExitError(e) && e.code === 1) { * return false * } * throw e * } */ export declare function isSpawnExitError(value: unknown): value is SpawnError & { code: number; };