All files / if-run/util helpers.ts

100% Statements 20/20
100% Branches 5/5
100% Functions 2/2
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 423x   3x   3x   3x         3x 2x   2x   2x 1x   1x             3x 11x   11x 20x 7x     20x 2x       11x    
import {ERRORS} from '@grnsft/if-core/utils';
 
import {logger} from '../../common/util/logger';
 
import {STRINGS} from '../config';
 
const {UNSUPPORTED_ERROR} = STRINGS;
 
/**
 * Impact engine error handler. Logs errors and appends issue template if error is unknown.
 */
export const andHandle = (error: Error) => {
  const knownErrors = Object.keys(ERRORS);
 
  logger.error(error);
 
  if (!knownErrors.includes(error.name)) {
    logger.error(UNSUPPORTED_ERROR(error.name));
    // eslint-disable-next-line no-process-exit
    process.exit(2);
  }
};
 
/**
 * Append entries from defaults which are missing from inputs.
 */
export const mergeObjects = (defaults: any, input: any) => {
  const merged: Record<string, any> = structuredClone(input);
 
  for (const key in defaults) {
    if (!(key in input)) {
      merged[key] = defaults[key];
    }
 
    if (merged[key] === undefined || merged[key] === null) {
      merged[key] = defaults[key];
    }
  }
 
  return merged;
};