All files / src/orm apollo_error.js

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 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 1801x   1x                                                                                                                                                                                                                                                                                                                             1x   8x 4x 4x   4x 4x       4x 4x   4x     1x  
const util = require('util');
 
const AERROR_TYPES = {
  unspecified: {
    msg: 'Unspecified error ->',
  },
  'model.validator.invalidconfig': {
    msg: '%s',
  },
  'model.validator.invalidudt': {
    msg: '%s',
  },
  'model.validator.invalidudf': {
    msg: '%s',
  },
  'model.validator.invaliduda': {
    msg: '%s',
  },
  'model.validator.invalidschema': {
    msg: '%s',
  },
  'model.validator.invalidvalue': {
    msg: '%s',
  },
  'model.tablecreation.invalidname': {
    msg: 'Table names only allow alphanumeric and _ and must start with a letter, got %s',
  },
  'model.tablecreation.dbschemaquery': {
    msg: 'Error while retrieveing Schema of DB Table "%s"',
  },
  'model.tablecreation.schemamismatch': {
    msg: 'Given Schema does not match existing DB Table "%s"\n%s',
  },
  'model.tablecreation.schemanotfound': {
    msg: 'No DB Table was found for Given Schema -> %s',
  },
  'model.tablecreation.dbcreate': {
    msg: 'Error while creating DB Table -> %s',
  },
  'model.tablecreation.dbalter': {
    msg: 'Error while altering DB Table -> %s',
  },
  'model.tablecreation.dbdrop': {
    msg: 'Error while dropping DB Table -> %s',
  },
  'model.tablecreation.dbindexcreate': {
    msg: 'Error while creating index on DB Table -> %s',
  },
  'model.tablecreation.dbindexdrop': {
    msg: 'Error while dropping index on DB Table -> %s',
  },
  'model.tablecreation.matviewcreate': {
    msg: 'Error while creating materialized view on DB Table -> %s',
  },
  'model.tablecreation.matviewdrop': {
    msg: 'Error while dropping materialized view on DB Table -> %s',
  },
  'model.find.invalidop': {
    msg: 'Invalid field relation: unknown operator: "%s"',
  },
  'model.find.invalidexpr': {
    msg: '$expr must be an object containing the index name as string and query as string.',
  },
  'model.find.invalidsolrquery': {
    msg: '$solr_query must be a string containing the query for solr.',
  },
  'model.find.invalidorder': {
    msg: 'Invalid $orderby query, $orderby must be an object',
  },
  'model.find.invalidgroup': {
    msg: 'Invalid $groupby query, $groupby must be an array',
  },
  'model.find.multiorder': {
    msg: 'Invalid $orderby query: only one clause per object is allowed',
  },
  'model.find.invalidordertype': {
    msg: 'Invalid $orderby query, allowed order: $asc / $desc, given "%s"',
  },
  'model.find.limittype': {
    msg: '$limit must be an integer, given value "%s"',
  },
  'model.find.invalidinop': {
    msg: 'Invalid $in query. $in must be an array',
  },
  'model.find.invalidcontainsop': {
    msg: 'Invalid $contains query, $contains operator is only valid for indexed collections',
  },
  'model.find.invalidcontainskeyop': {
    msg: 'Invalid $contains_key query, $contains_key operator is only valid for indexed map collections',
  },
  'model.find.invalidtoken': {
    msg: 'Invalid $token query. $token must be an object with operator values',
  },
  'model.find.invalidtokenop': {
    msg: 'Invalid operator: "%s" in $token query',
  },
  'model.find.streamerror': {
    msg: 'Invalid stream query -> %s',
  },
  'model.find.eachrowerror': {
    msg: 'Invalid eachRow query -> %s',
  },
  'model.find.cberror': {
    msg: 'No valid callback function was provided',
  },
  'model.find.dberror': {
    msg: 'Error during find query on DB -> %s',
  },
  'model.save.unsetkey': {
    msg: 'Primary Key Field: %s must have a value',
  },
  'model.save.unsetrequired': {
    msg: 'Required Field: %s must have a value',
  },
  'model.save.invaliddefaultvalue': {
    msg: 'Invalid Default value: "%s" for Field: %s (Type: %s)',
  },
  'model.save.dberror': {
    msg: 'Error during save query on DB -> %s',
  },
  'model.save.before.error': {
    msg: 'Error in before_save lifecycle function',
  },
  'model.save.after.error': {
    msg: 'Error in after_save lifecycle function',
  },
  'model.update.unsetkey': {
    msg: 'Primary Key Field: %s must have a value',
  },
  'model.update.unsetrequired': {
    msg: 'Required Field: %s must have a value',
  },
  'model.update.invaliddefaultvalue': {
    msg: 'Invalid Default value: "%s" for Field: %s (Type: %s)',
  },
  'model.update.invalidreplaceop': {
    msg: 'Invalid $replace operation -> %s',
  },
  'model.update.invalidprependop': {
    msg: 'Invalid $prepend operation -> %s',
  },
  'model.update.dberror': {
    msg: 'Error during update query on DB -> %s',
  },
  'model.update.before.error': {
    msg: 'Error in before_update lifecycle function',
  },
  'model.update.after.error': {
    msg: 'Error in after_update lifecycle function',
  },
  'model.delete.dberror': {
    msg: 'Error during delete query on DB -> %s',
  },
  'model.delete.before.error': {
    msg: 'Error in before_delete lifecycle function',
  },
  'model.delete.after.error': {
    msg: 'Error in after_delete lifecycle function',
  },
};
 
const ERR_NAME_PREFIX = 'apollo';
 
const buildError = function f(...args) {
  const argsarray = args;
  const name = argsarray.length ? argsarray.shift() : '_none_given_';
 
  const errorTemplate = AERROR_TYPES[name] || AERROR_TYPES.unspecified;
  const errorMsg = argsarray.length ?
    util.format.apply(this, [errorTemplate.msg].concat(argsarray)) :
    errorTemplate.msg;
 
  const error = new Error(errorMsg);
  error.name = (ERR_NAME_PREFIX ? util.format('%s.', ERR_NAME_PREFIX) : '') + name;
 
  return error;
};
 
module.exports = buildError;