Code coverage report for core/src/errors/invalid-arg.ts

Statements: 7.69% (1 / 13)      Branches: 0% (0 / 17)      Functions: 0% (0 / 2)      Lines: 7.69% (1 / 13)      Ignored: none     

All files » core/src/errors/ » invalid-arg.ts
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 401                                                                              
export class InvalidArg extends Error {
 
  constructor(
    message: string,
    readonly argName?: string,
    readonly actual?: unknown,
    readonly expected?: unknown) {
    super(message);
  }
 
  static expected(
    argName: string,
    actual: unknown,
    expected: unknown,
    additionalDetails = ''
  ): Error {
    let exp;
    let act;
 
    if (typeof actual === 'object') {
      act = actual?.toString() || null;
    } else {
      act = actual;
    }
    if (typeof expected === 'object') {
      exp = expected?.toString() || null;
    } else {
      exp = expected;
    }
 
    const msg = `Invalid argument "${argName}! Expected "${exp}" but was "${act}! ${additionalDetails}"`
    return new InvalidArg(
      msg,
      argName,
      actual,
      expected
    );
 
  }
}