All files / src errors.ts

100% Statements 18/18
100% Branches 3/3
100% Functions 3/3
100% Lines 18/18

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64                                                    1x 1x 48x         48x 48x 1x                 1x 1x 20x 20x 20x 1x               1x 1x 5x 5x 5x 1x  
/**
 * Exception classes for pgrls-test.
 *
 * A small hierarchy: every error pgrls-test throws inherits from
 * `PgrlsTestError`, so callers can `catch (e) { if (e instanceof
 * PgrlsTestError) … }` to catch any.
 *
 * **Why not extend Node's `AssertionError`?** Vitest matches errors
 * by name + message pattern, not by the Node-specific
 * `AssertionError` shape. The parent chain
 * `PgrlsTestAssertionError → PgrlsTestError → Error` renders
 * cleanly in Vitest's diff output without coupling us to Node's
 * `assert` module.
 *
 * Mirrors `pgrls.testing.errors` (Python). The class hierarchy is
 * intentionally identical so the conformance suite can compare
 * "exception thrown vs raised" assertions byte-for-byte across the
 * two languages.
 */
 
/**
 * Base class for every error thrown inside pgrls-test.
 *
 * Catch this (`catch (e) { if (e instanceof PgrlsTestError) … }`)
 * to handle any pgrls-test error uniformly.
 */
export class PgrlsTestError extends Error {
  constructor(message: string) {
    super(message);
    // V8's `Error` doesn't auto-set `name` from the constructor;
    // assign it explicitly so stack traces and serialization
    // (e.g. JSON.stringify) carry the subclass name rather than
    // a generic "Error".
    this.name = 'PgrlsTestError';
  }
}
 
/**
 * Thrown by `assert*` helpers when their precondition fails.
 *
 * Vitest renders this as a normal test failure (no special
 * AssertionError handling needed); its message is the diff /
 * description of what didn't match.
 */
export class PgrlsTestAssertionError extends PgrlsTestError {
  constructor(message: string) {
    super(message);
    this.name = 'PgrlsTestAssertionError';
  }
}
 
/**
 * Thrown when pgrls-test has no database URL or driver to use.
 *
 * Surfaced when the test setup hasn't supplied a connection /
 * driver, or when an env-var fallback comes back empty.
 */
export class PgrlsTestConfigError extends PgrlsTestError {
  constructor(message: string) {
    super(message);
    this.name = 'PgrlsTestConfigError';
  }
}