/** * Canonical helper for converting caught errors to {@link EngineResult} failures * with the real LAFS error code preserved. * * Generalizes the T9838-D fix that was applied inline in `tasks/update.ts` * to ALL engine-result wrappers across the tasks domain. Before this * SSoT, every catch block in `tasks/*.ts` was blanket-labelling errors as * `E_NOT_INITIALIZED`, hiding the real failure mode whenever a * {@link CleoError} (e.g. `T877_INVARIANT_VIOLATION`, validation rejects, * DB trigger violations) bubbled out of `coreTask*` functions. * * Use this helper in every `try { … } catch (err: unknown) { … }` block * where the body returns an `EngineResult`. Non-CleoError values fall * through to the supplied `fallbackCode`. * * @task T9940 * @epic T9862 */ import { type EngineResult } from './engine-result.js'; /** * Convert a caught value into an {@link EngineResult} failure. * * - When the caught value is a {@link CleoError}, the LAFS code from * `toLAFSError()` (`E_CLEO_VALIDATION`, `E_CLEO_NOT_FOUND`, etc.) is * used. The original numeric `code` is forwarded as `exitCode`, and the * rich `fix` / `alternatives` / `details` fields are propagated. * - When the caught value is NOT a CleoError (e.g. a plain `Error`, a * string, or `null`), the supplied `fallbackCode` and `fallbackMessage` * are used. The default `fallbackCode` is `'E_INTERNAL'`, which is more * diagnostic than the historic `'E_NOT_INITIALIZED'` blanket label. * * @param err - The caught error value (type `unknown`). * @param fallbackCode - LAFS code used when `err` is not a CleoError. * Defaults to `'E_INTERNAL'`. * @param fallbackMessage - Human-readable message used when `err.message` * is absent. Defaults to `'Operation failed'`. * @returns A failure-shaped {@link EngineResult}. * * @example * ```ts * try { * const result = await coreTaskCancel(projectRoot, taskId); * return engineSuccess(result); * } catch (err: unknown) { * return cleoErrorToEngineResult(err, 'E_INTERNAL', 'Failed to cancel task'); * } * ``` * * @task T9940 */ export declare function cleoErrorToEngineResult(err: unknown, fallbackCode?: string, fallbackMessage?: string): EngineResult; /** * The {@link EngineResult} for a write refused because the store still owes * its legacy migration (an {@link ExodusAbortWriteUnsafeError}: exodus-on-open * deferred or aborted), keeping its code (`E_EXODUS_DEFERRED_WRITE_UNSAFE` / * `E_EXODUS_ABORT_WRITE_UNSAFE`), message and remedy; or an open refused * because such a store could not be guarded ({@link ExodusGuardFailedError}, * `E_EXODUS_GUARD_FAILED`, T13171). `null` for any other * value, so a catch block can fall through to its own handling. * * @param err - The caught value. * @returns The refusal result, or `null`. * @example * ```ts * } catch (err) { * return exodusRefusalToEngineResult(err) ?? engineError('E_INTERNAL', 'failed'); * } * ``` * @task T13167 */ export declare function exodusRefusalToEngineResult(err: unknown): EngineResult | null; //# sourceMappingURL=errors-to-engine.d.ts.map