/*
Error parser for create and update.
176398
function parseChangeError(e, modelObj) {
    if (e && e.name.indexOf('Thorin') === 0) return e;
    let wrapError = thorin.error('INPUT.NOT_VALID', 'Invalid value for entity.', 400),
      fields = [];
    if (e instanceof Error) {
      switch (e.name) {
        case 'SequelizeValidationError':
          wrapError.message = e.errors[0].message;
          e.errors.forEach((err) => {
            if (err.path.indexOf('thorinValidate') === -1) { // field validator.
              fields.push(err.path);
            }
          });
          break;
        case 'SequelizeUniqueConstraintError':
          wrapError.code = 'INPUT.EXISTS';
          wrapError.message = "An entry with the same " + e.errors[0].path.substr(modelObj.tableName.length + 1) + ' already exists.';
          e.errors.forEach((err) => {
            fields.push(err.path.substr(modelObj.tableName.length + 1));
          });
          break;
        default:
          e = thorin.error(e);  // default error.
      }
    }
    if (fields.length === 1) {
      wrapError.data = {
        field: fields[0]
      }
    } else if (fields.length > 1) {
      wrapError.data = {
        fields: fields
      };
    }
    return wrapError;
  }
982477
function createErrorMessage(errorcode) {
	if (errorcode in ERRORS) {
		var args = Array.prototype.slice.call(arguments,1);
		var entry = ERRORS[errorcode];
		if (entry.argcount && entry.argcount!==args.length) {
			// this should only ever get called if we have a bug in this library
			throw new Error("Internal failure. Unexpected usage of internal command. Please report error code: "+errorcode+"(invalid args) to the developer with the following stack trace:"+new Error().stack);
		}
		return new RequestSSLError((args.length ? util.format.apply(util.format,[entry.message].concat(args)) : entry.message), errorcode);
	}
	else {
		// this should only ever get called if we have a bug in this library
		throw new Error("Internal failure. Unexpected usage of internal command. Please report error code: "+errorcode+"(invalid error code) to the developer with the following stack trace:"+new Error().stack);
	}
}
893498
function error( message, errors ) {
      const trim = _ => _.replace( /^\s+/, '' ).replace( /\s+$/, '' );
      const ajvMessage = ajv.errorsText( errors, { dataVar: '' } );
      const error = new Error(
         `${message}: ${trim(ajvMessage)} ${JSON.stringify(errors.map(e => e.params))}`
      );
      error.name = 'ValidationError';
      error.errors = errors;
      return error;
   }
795522
function error (err, file, name, options) {
  var message = err.message
  var column = err.column
  var line = err.line
  var type = err.name
  var method = 'message'

  if (options.throws) {
    method = 'fail'
  }

  file[method](
    message,
    { line: line, column: column },
    'parseFrontMatter:' + name + ':' + type
  )
}
966096
function makeError(id, msg, err) {
        var e = new Error(msg + '\nhttp://requirejs.org/docs/errors.html#' + id);
        if (err) {
            e.originalError = err;
        }
        return e;
    }
233472
function errHandler(err, req, res) {
    if (!err.status) { log(err); }
    error(err.status || 500, req, res, u.str(err));
  }
421312
function buildErrorHandler(path) {
    return function(node, text) {
        throw path.hub.file.buildCodeFrameError(node, text);
    }
}
62867
function error (message, error) {
    // build custom error message
    message = `${this.model.name}#${this.id} record error` + (
        typeof message === 'string'
            ? `: ${message}`
            : ''
    )
    // use error object passed in
    if (defined(error)) {
        // create data object with original message
        error.data = {
            message: error.message,
        }
    }
    // create new error message
    else {
        error = new Error(message)
        error.data = {}
    }
    // set record data for error
    error.data.record = this

    return error
}
374491
function handleError(err, msg, code, req, res){
  logError(err, msg, code, req);

  var response = buildErrorObject({
    err: err,
    msg: msg,
    httpCode: code
  });

  res.statusCode = response.httpCode;
  res.end(JSON.stringify(response.errorFields));
}
695896
function _buildError(url, status, method, response) {
    var errorData = response || {};

    errorData.status = status;
    errorData.url = url;
    errorData.method = method;

    return errorData;
  }
770149
function createError(status, message) {
  var err = new Error(message);
  err.status = status;
  return err;
}
645606
function error () {
  if (mocking) {
    cli.stderr += stripAnsi(concatArguments(arguments) + '\n')
  } else {
    console.error.apply(null, arguments)
  }
}
935708
function unhandledErrorListener(err, namespace) {
  console.error('[distribucache] (%s) error from an unhandled ' +
    '`error` event:\n', namespace, err && err.stack || err);
}
1114270
function createSyntaxError (message, c) {
  if (c === undefined) {
    c = index - token.length;
  }
  let error = new SyntaxError(message + ' (char ' + c + ')');
  error['char'] = c;

  return error;
}
56819
function createError (err, target) {
  return { status: 'error', target: target, message: err, timestamp: Date.now() }
}
797732
function errors() {
        // handling 404 errors from config.express['404_redirect'] property
        if (config['404_redirect']) {
            server.use(function (req, res, next) {
                res.status(302)
                res.writeHead(302, { 'Location': config['404_redirect'] })
                res.end()
            })
        } else {
            server.use(function (req, res, next) {
                res.status(404).send({ message: 'not found' })
            })
        }

        if (errorHandlers.length) {
            for (let eh of errorHandlers) {
                server.use(wrapper(eh))
            }
        }

        //Default error handler
        server.use((err, req, res, next) => {
            if (!config.silent && !errorHandlers.length)
                app.drivers.logger.error('Unhandled server error', err)
            res.status(500)
               .json({
                   message: err.message,
                   stack: process.env.NODE_ENV === 'production' ? undefined : err.stack
               })
        })
    }
1270647
function parseError(error: Error | string | string[]): StackFrame[] {
  if (error == null) {
    throw new Error('You cannot pass a null object.')
  }
  if (typeof error === 'string') {
    return parseStack(error.split('\n'))
  }
  if (Array.isArray(error)) {
    return parseStack(error)
  }
  if (typeof error.stack === 'string') {
    return parseStack(error.stack.split('\n'))
  }
  throw new Error('The error you provided does not contain a stack trace.')
}