Files
msd-core/sdk/src/errors.ts
Tom Boucher 002bcf2a8a fix(2137): skip worktree isolation when .gitmodules detected (#2144)
* feat(sdk): add typed query foundation and gsd-sdk query (Phase 1)

Add sdk/src/query registry and handlers with tests, GSDQueryError, CLI query wiring, and supporting type/tool-scoping hooks. Update CHANGELOG. Vitest 4 constructor mock fixes in milestone-runner tests.

Made-with: Cursor

* fix(2137): skip worktree isolation when .gitmodules detected

When a project contains git submodules, worktree isolation cannot
correctly handle submodule commits — three separate gaps exist in
worktree setup, executor commit protocol, and merge-back. Rather
than patch each gap individually, detect .gitmodules at phase start
and fall back to sequential execution, which handles submodules
transparently (Option B).

Affected workflows: execute-phase.md, quick.md

---------

Co-authored-by: David Sienkowski <dave@sienkowski.com>
2026-04-12 08:33:04 -04:00

73 lines
2.6 KiB
TypeScript

/**
* Error classification system for the GSD SDK.
*
* Provides a taxonomy of error types with semantic exit codes,
* enabling CLI consumers and agents to distinguish between
* validation failures, execution errors, blocked states, and
* interruptions.
*
* @example
* ```typescript
* import { GSDError, ErrorClassification, exitCodeFor } from './errors.js';
*
* throw new GSDError('missing required arg', ErrorClassification.Validation);
* // CLI catch handler: process.exitCode = exitCodeFor(err.classification); // 10
* ```
*/
// ─── Error Classification ───────────────────────────────────────────────────
/** Classifies SDK errors into semantic categories for exit code mapping. */
export enum ErrorClassification {
/** Bad input, missing args, schema violations. Exit code 10. */
Validation = 'validation',
/** Runtime failure, file I/O, parse errors. Exit code 1. */
Execution = 'execution',
/** Dependency missing, phase not found. Exit code 11. */
Blocked = 'blocked',
/** Timeout, signal, user cancel. Exit code 1. */
Interruption = 'interruption',
}
// ─── GSDError ───────────────────────────────────────────────────────────────
/**
* Base error class for the GSD SDK with classification support.
*
* @param message - Human-readable error description
* @param classification - Error category for exit code mapping
*/
export class GSDError extends Error {
readonly name = 'GSDError';
readonly classification: ErrorClassification;
constructor(message: string, classification: ErrorClassification) {
super(message);
this.classification = classification;
}
}
// ─── Exit code mapping ──────────────────────────────────────────────────────
/**
* Maps an error classification to a semantic exit code.
*
* @param classification - The error classification to map
* @returns Numeric exit code: 10 (validation), 11 (blocked), 1 (execution/interruption)
*/
export function exitCodeFor(classification: ErrorClassification): number {
switch (classification) {
case ErrorClassification.Validation:
return 10;
case ErrorClassification.Blocked:
return 11;
case ErrorClassification.Execution:
case ErrorClassification.Interruption:
default:
return 1;
}
}