All files / mongoose/lib/error setOptionError.js

40.9% Statements 9/22
25% Branches 1/4
0% Functions 0/6
40.9% Lines 9/22

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 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            1x 1x 1x                                                                                                           1x   1x               1x                   1x                           1x           1x  
/*!
 * Module requirements
 */
 
'use strict';
 
const MongooseError = require('./mongooseError');
const util = require('util');
const combinePathErrors = require('../helpers/error/combinePathErrors');
 
/**
 * Mongoose.set Error
 *
 * @api private
 * @inherits MongooseError
 */
 
class SetOptionError extends MongooseError {
 
  constructor() {
    super('');
 
    this.errors = {};
  }
 
  /**
   * Console.log helper
   */
  toString() {
    return combinePathErrors(this);
  }
 
  /**
   * inspect helper
   * @api private
   */
  inspect() {
    return Object.assign(new Error(this.message), this);
  }
 
  /**
  * add message
  * @param {String} key
  * @param {String|Error} error
  * @api private
  */
  addError(key, error) {
    if (error instanceof SetOptionError) {
      const { errors } = error;
      for (const optionKey of Object.keys(errors)) {
        this.addError(optionKey, errors[optionKey]);
      }
 
      return;
    }
 
    this.errors[key] = error;
    this.message = combinePathErrors(this);
  }
}
 
 
Eif (util.inspect.custom) {
  // Avoid Node deprecation warning DEP0079
  SetOptionError.prototype[util.inspect.custom] = SetOptionError.prototype.inspect;
}
 
/**
 * Helper for JSON.stringify
 * Ensure `name` and `message` show up in toJSON output re: gh-9847
 * @api private
 */
Object.defineProperty(SetOptionError.prototype, 'toJSON', {
  enumerable: false,
  writable: false,
  configurable: true,
  value: function() {
    return Object.assign({}, this, { name: this.name, message: this.message });
  }
});
 
 
Object.defineProperty(SetOptionError.prototype, 'name', {
  value: 'SetOptionError'
});
 
class SetOptionInnerError extends MongooseError {
  /**
   * Error for the "errors" array in "SetOptionError" with consistent message
   * @param {String} key
   */
  constructor(key) {
    super(`"${key}" is not a valid option to set`);
  }
}
 
SetOptionError.SetOptionInnerError = SetOptionInnerError;
 
/*!
 * Module exports
 */
 
module.exports = SetOptionError;