All files / src errors.ts

46.02% Statements 52/113
9.09% Branches 2/22
24.24% Functions 8/33
47.57% Lines 49/103
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 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210      2x                           2x 2x     2x                           2x 2x     2x                           2x 2x     2x                                       89x   2x     2x       78x 78x 78x 78x   78x   78x 78x     78x       2x   6x   2x       2x 2x 2x 2x   2x   2x 2x     2x       14x   2x 2x 1x   2x                           2x 2x     2x                                   2x         2x 1x   2x                           2x 2x     2x                           2x 2x    
import * as t from "io-ts";
import { QueryConfig } from "pg";
 
export class PgPoolCheckoutError extends Error {
  public readonly _PgPoolCheckoutError: void;
 
  constructor(public readonly error: t.mixed) {
    super("Unable to checkout a connection from the pool.");
 
    if (Error.captureStackTrace) {
      Error.captureStackTrace(this, PgPoolCheckoutError);
    }
 
    this.name = this.constructor.name;
  }
}
 
export const makePoolCheckoutError = (e: t.mixed) => new PgPoolCheckoutError(e);
export const isPoolCheckoutError = (e: t.mixed): e is PgPoolCheckoutError =>
  e instanceof PgPoolCheckoutError;
 
export class PgPoolCreationError extends Error {
  public readonly _PgPoolCreationError: void;
 
  constructor(public readonly error: t.mixed) {
    super("Unable to create a connection pool.");
 
    if (Error.captureStackTrace) {
      Error.captureStackTrace(this, PgPoolCreationError);
    }
 
    this.name = this.constructor.name;
  }
}
 
export const makePoolCreationError = (e: t.mixed) => new PgPoolCreationError(e);
export const isPoolCreationError = (e: t.mixed): e is PgPoolCreationError =>
  e instanceof PgPoolCreationError;
 
export class PgPoolShutdownError extends Error {
  public readonly _PgPoolShutdownError: void;
 
  constructor(public readonly error: t.mixed) {
    super("Unable to shutdown a connection pool.");
 
    if (Error.captureStackTrace) {
      Error.captureStackTrace(this, PgPoolShutdownError);
    }
 
    this.name = this.constructor.name;
  }
}
 
export const makePoolShutdownError = (e: t.mixed) => new PgPoolShutdownError(e);
export const isPoolShutdownError = (e: t.mixed): e is PgPoolShutdownError =>
  e instanceof PgPoolShutdownError;
 
export class PgDriverQueryError extends Error {
  public readonly _PgDriverQueryError: void;
 
  constructor(
    public readonly error: t.mixed,
    public readonly query: QueryConfig,
    public readonly context: t.mixed,
  ) {
    super(
      error instanceof Error ? error.message : "Error raised by node-pg during query execution.",
    );
 
    if (Error.captureStackTrace) {
      Error.captureStackTrace(this, PgDriverQueryError);
    }
 
    this.name = this.constructor.name;
  }
}
 
export const makeDriverQueryError = (query: QueryConfig, context: t.mixed) => (e: t.mixed) =>
  new PgDriverQueryError(e, query, context);
export const isDriverQueryError = (e: t.mixed): e is PgDriverQueryError =>
  e instanceof PgDriverQueryError;
 
export class PgRowCountError extends Error {
  public readonly _PgRowCountError: void;
 
  constructor(
    public readonly query: QueryConfig,
    public readonly expected: string,
    public readonly received: string,
    public readonly context: t.mixed,
  ) {
    super("Query returned an unexpected number of rows.");
 
    Eif (Error.captureStackTrace) {
      Error.captureStackTrace(this, PgRowCountError);
    }
 
    this.name = this.constructor.name;
  }
}
 
export const makeRowCountError = (query: QueryConfig, context: t.mixed) => (e: t.mixed) =>
  new PgDriverQueryError(e, query, context);
export const isRowCountError = (e: t.mixed): e is PgRowCountError => e instanceof PgRowCountError;
 
export class PgRowValidationError extends Error {
  public readonly _PgRowValidationError: void;
 
  constructor(
    public readonly type: t.Any,
    public readonly value: t.mixed,
    public readonly errors: t.Errors,
    public readonly context: t.mixed,
  ) {
    super("Validation of a result row failed.");
 
    Eif (Error.captureStackTrace) {
      Error.captureStackTrace(this, PgRowValidationError);
    }
 
    this.name = this.constructor.name;
  }
}
 
export const makeRowValidationError = (type: t.Any, value: t.mixed, context: t.mixed) => (
  errors: t.Errors,
) => new PgRowValidationError(type, value, errors, context);
export const isRowValidationError = (e: t.mixed): e is PgRowValidationError =>
  e instanceof PgRowValidationError;
 
export class PgTypeParserSetupError extends Error {
  public readonly _PgTypeParserSetupError: void;
 
  constructor(public readonly error: t.mixed) {
    super("Type parser setup failed.");
 
    if (Error.captureStackTrace) {
      Error.captureStackTrace(this, PgTypeParserSetupError);
    }
 
    this.name = this.constructor.name;
  }
}
 
export const makeTypeParserSetupError = (e: t.mixed) => new PgTypeParserSetupError(e);
export const isTypeParserSetupError = (e: t.mixed): e is PgTypeParserSetupError =>
  e instanceof PgTypeParserSetupError;
 
export class PgTransactionRollbackError extends Error {
  public readonly _PgTransactionRollbackError: void;
 
  constructor(
    public readonly rollbackError: t.mixed,
    public readonly connectionError: t.mixed,
    public readonly context: t.mixed,
  ) {
    super("A ROLLBACK was requested but not successfully completed.");
 
    if (Error.captureStackTrace) {
      Error.captureStackTrace(this, PgTransactionRollbackError);
    }
 
    this.name = this.constructor.name;
  }
}
 
export const makeTransactionRollbackError = (
  rollbackError: t.mixed,
  connectionError: t.mixed,
  context: t.mixed,
) => new PgTransactionRollbackError(rollbackError, connectionError, context);
export const isTransactionRollbackError = (e: t.mixed): e is PgTransactionRollbackError =>
  e instanceof PgTransactionRollbackError;
 
export class PgUnhandledConnectionError extends Error {
  public readonly _PgUnhandledConnectionError: void;
 
  constructor(public readonly error: t.mixed) {
    super("An unhandled error was raised by a connection.");
 
    if (Error.captureStackTrace) {
      Error.captureStackTrace(this, PgUnhandledConnectionError);
    }
 
    this.name = this.constructor.name;
  }
}
 
export const makeUnhandledConnectionError = (e: t.mixed) => new PgUnhandledConnectionError(e);
export const isUnhandledConnectionError = (e: t.mixed): e is PgUnhandledConnectionError =>
  e instanceof PgUnhandledConnectionError;
 
export class PgUnhandledPoolError extends Error {
  public readonly _PgUnhandledPoolError: void;
 
  constructor(public readonly error: t.mixed) {
    super("An unhandled error was raised by a connection pool.");
 
    if (Error.captureStackTrace) {
      Error.captureStackTrace(this, PgUnhandledPoolError);
    }
 
    this.name = this.constructor.name;
  }
}
 
export const makeUnhandledPoolError = (e: t.mixed) => new PgUnhandledPoolError(e);
export const isUnhandledPoolError = (e: t.mixed): e is PgUnhandledPoolError =>
  e instanceof PgUnhandledPoolError;