<commit_before>var helper = require(__dirname+'/helper.js');
var INDENT = 4;
var LIMIT = 80;
var IS_OPERATIONAL = 'isOperational';

var protodef = require(__dirname+'/protodef.js');
var responseTypes = protodef.Response.ResponseType;
var protoErrorType = protodef.Response.ErrorType;
var termTypes = protodef.Term.TermType;
var datumTypes = protodef.Datum.DatumType;
var frameTypes = protodef.Frame.FrameType;


function ReqlDriverError(message, query, secondMessage) {
  Error.captureStackTrace(this, ReqlDriverError);
  this.message = this.msg = message;

  if ((Array.isArray(query) && (query.length > 0)) || (!Array.isArray(query) && query != null)) {
    if ((this.message.length > 0) && (this.message[this.message.length-1] === '.')) {
      this.message = this.message.slice(0, this.message.length-1);
    }
    
    this.message += ' after:\n';

    var backtrace = generateBacktrace(query, 0, null, [], {indent: 0, extra: 0});

    this.message += backtrace.str;
  }
  else {
    if (this.message[this.message.length-1] !== '?') this.message += '.';
  }
  if (secondMessage) this.message += '\n'+secondMessage;
};
ReqlDriverError.prototype = new Error();
ReqlDriverError.prototype.name = 'ReqlDriverError';
ReqlDriverError.prototype.setOperational = function() {
  this[IS_OPERATIONAL] = true;
  return this;
};

module.exports.ReqlDriverError = ReqlDriverError;


function ReqlServerError(message, query) {
  Error.captureStackTrace(this, ReqlServerError);
  this.message = this.msg = message;

  if ((Array.isArray(query) && (query.length > 0)) || (!Array.isArray(query) && query != null)) {
    if ((this.message.length > 0) && (this.message[this.message.length-1] === '.')) {
      this.message = this.message.slice(0, this.message.length-1);
    }
    
    this.message += ' for:\n';

    var backtrace = generateBacktrace(query, 0, null, [], {indent: 0, extra: 0});

    this.message += backtrace.str;
  }
  else {
    if (this.message[this.message.length-1] !== '?') this.message += '.';
  }
};
ReqlServerError.prototype = new Error();
ReqlServerError.prototype.name = 'ReqlServerError';
ReqlServerError.prototype[IS_OPERATIONAL] = true;

module.exports.ReqlServerError = ReqlServerError;


function ReqlRuntimeError(message, query, frames) {
  Error.captureStackTrace(this, ReqlRuntimeError);
  this.message = this.msg = message;

  if ((query != null) && (frames)) {
    if ((this.message.length > 0) && (this.message[this.message.length-1] === '.')) {
      this.message = this.message.slice(0, this.message.length-1);
    }
    
    this.message += ' in:\n';

    frames = frames.b;
    if (frames) this.frames = frames.slice(0);
    //this.frames = JSON.stringify(frames, null, 2);

    var backtrace = generateBacktrace(query, 0, null, frames, {indent: 0, extra: 0});

    var queryLines = backtrace.str.split('\n');
    var carrotLines = backtrace.car.split('\n');

    for(var i=0; i<queryLines.length; i++) {
      this.message += queryLines[i]+'\n';
      if (carrotLines[i].match(/\^/)) {
        var pos = queryLines[i].match(/[^\s]/);
        if ((pos) && (pos.index)) {
          this.message += space(pos.index)+carrotLines[i].slice(pos.index)+'\n';
        }
        else {
          this.message += carrotLines[i]+'\n';
        }
      }
    }
  }
  //this.query = JSON.stringify(query, null, 2);
};
ReqlRuntimeError.prototype = new Error();
ReqlRuntimeError.prototype.name = 'ReqlRuntimeError';
ReqlRuntimeError.prototype.setName = function(type) {
  switch(type) {
    case protoErrorType.INTERNAL:
      this.name = 'ReqlInternalError';
      break;
    case protoErrorType.RESOURCE_LIMIT:
      this.name = 'ReqlResourceError';
      break;
    case protoErrorType.QUERY_LOGIC:
      this.name = 'ReqlLogicError';
      break;
    case protoErrorType.OP_FAILED:
      this.name = 'ReqlOpFailedError';
      break;
    case protoErrorType.OP_INDETERMINATE:
      this.name = 'ReqlOpIndeterminateError';
      break;
    case protoErrorType.USER:
      this.name = 'ReqlUserError';
      break;
    //default: // Do nothing
  }
}
ReqlRuntimeError.prototype[IS_OPERATIONAL] = true;

module.exports.ReqlRuntimeError = ReqlRuntimeError;


function ReqlCompileError(message, query, frames) {
  Error.captureStackTrace(this, ReqlCompileError);
  this.message = message;

  if ((query != null) && (frames)) {
    if ((this.message.length > 0) && (this.message[this.message.length-1] === '.')) {
      this.message = this.message.slice(0, this.message.length-1);
    }

    this.message += ' in:\n';

    frames = frames.b;
    if (frames) this.frames = frames.slice(0);
    //this.frames = JSON.stringify(frames, null, 2);

    var backtrace = generateBacktrace(query, 0, null, frames, {indent: 0, extra: 0});

    var queryLines = backtrace.str.split('\n');
    var carrotLines = backtrace.car.split('\n');

    for(var i=0; i<queryLines.length; i++) {
      this.message += queryLines[i]+'\n';
      if (carrotLines[i].match(/\^/)) {
        var pos = queryLines[i].match(/[^\s]/);
        if ((pos) && (pos.index)) {
          this.message += space(pos.index)+carrotLines[i].slice(pos.index)+'\n';
        }
        else {
          this.message += carrotLines[i]+'\n';
        }
      }
    }
  }
};
ReqlCompileError.prototype = new Error();
ReqlCompileError.prototype.name = 'ReqlCompileError';
ReqlCompileError.prototype[IS_OPERATIONAL] = true;

module.exports.ReqlCompileError = ReqlCompileError;


function ReqlClientError(message) {
  Error.captureStackTrace(this, ReqlClientError);
  this.message = message;
};
ReqlClientError.prototype = new Error();
ReqlClientError.prototype.name = 'ReqlClientError';
ReqlClientError.prototype[IS_OPERATIONAL] = true;

module.exports.ReqlClientError = ReqlClientError;



var _constants = {<commit_msg>Call `Error.captureStackTrace` after `this.message` is set<commit_after>var helper = require(__dirname+'/helper.js');
var INDENT = 4;
var LIMIT = 80;
var IS_OPERATIONAL = 'isOperational';

var protodef = require(__dirname+'/protodef.js');
var responseTypes = protodef.Response.ResponseType;
var protoErrorType = protodef.Response.ErrorType;
var termTypes = protodef.Term.TermType;
var datumTypes = protodef.Datum.DatumType;
var frameTypes = protodef.Frame.FrameType;


function ReqlDriverError(message, query, secondMessage) {
  this.message = this.msg = message;
  Error.captureStackTrace(this, ReqlDriverError);

  if ((Array.isArray(query) && (query.length > 0)) || (!Array.isArray(query) && query != null)) {
    if ((this.message.length > 0) && (this.message[this.message.length-1] === '.')) {
      this.message = this.message.slice(0, this.message.length-1);
    }
    
    this.message += ' after:\n';

    var backtrace = generateBacktrace(query, 0, null, [], {indent: 0, extra: 0});

    this.message += backtrace.str;
  }
  else {
    if (this.message[this.message.length-1] !== '?') this.message += '.';
  }
  if (secondMessage) this.message += '\n'+secondMessage;
};
ReqlDriverError.prototype = new Error();
ReqlDriverError.prototype.name = 'ReqlDriverError';
ReqlDriverError.prototype.setOperational = function() {
  this[IS_OPERATIONAL] = true;
  return this;
};

module.exports.ReqlDriverError = ReqlDriverError;


function ReqlServerError(message, query) {
  this.message = this.msg = message;
  Error.captureStackTrace(this, ReqlServerError);

  if ((Array.isArray(query) && (query.length > 0)) || (!Array.isArray(query) && query != null)) {
    if ((this.message.length > 0) && (this.message[this.message.length-1] === '.')) {
      this.message = this.message.slice(0, this.message.length-1);
    }
    
    this.message += ' for:\n';

    var backtrace = generateBacktrace(query, 0, null, [], {indent: 0, extra: 0});

    this.message += backtrace.str;
  }
  else {
    if (this.message[this.message.length-1] !== '?') this.message += '.';
  }
};
ReqlServerError.prototype = new Error();
ReqlServerError.prototype.name = 'ReqlServerError';
ReqlServerError.prototype[IS_OPERATIONAL] = true;

module.exports.ReqlServerError = ReqlServerError;


function ReqlRuntimeError(message, query, frames) {
  this.message = this.msg = message;
  Error.captureStackTrace(this, ReqlRuntimeError);

  if ((query != null) && (frames)) {
    if ((this.message.length > 0) && (this.message[this.message.length-1] === '.')) {
      this.message = this.message.slice(0, this.message.length-1);
    }
    
    this.message += ' in:\n';

    frames = frames.b;
    if (frames) this.frames = frames.slice(0);
    //this.frames = JSON.stringify(frames, null, 2);

    var backtrace = generateBacktrace(query, 0, null, frames, {indent: 0, extra: 0});

    var queryLines = backtrace.str.split('\n');
    var carrotLines = backtrace.car.split('\n');

    for(var i=0; i<queryLines.length; i++) {
      this.message += queryLines[i]+'\n';
      if (carrotLines[i].match(/\^/)) {
        var pos = queryLines[i].match(/[^\s]/);
        if ((pos) && (pos.index)) {
          this.message += space(pos.index)+carrotLines[i].slice(pos.index)+'\n';
        }
        else {
          this.message += carrotLines[i]+'\n';
        }
      }
    }
  }
  //this.query = JSON.stringify(query, null, 2);
};
ReqlRuntimeError.prototype = new Error();
ReqlRuntimeError.prototype.name = 'ReqlRuntimeError';
ReqlRuntimeError.prototype.setName = function(type) {
  switch(type) {
    case protoErrorType.INTERNAL:
      this.name = 'ReqlInternalError';
      break;
    case protoErrorType.RESOURCE_LIMIT:
      this.name = 'ReqlResourceError';
      break;
    case protoErrorType.QUERY_LOGIC:
      this.name = 'ReqlLogicError';
      break;
    case protoErrorType.OP_FAILED:
      this.name = 'ReqlOpFailedError';
      break;
    case protoErrorType.OP_INDETERMINATE:
      this.name = 'ReqlOpIndeterminateError';
      break;
    case protoErrorType.USER:
      this.name = 'ReqlUserError';
      break;
    //default: // Do nothing
  }
}
ReqlRuntimeError.prototype[IS_OPERATIONAL] = true;

module.exports.ReqlRuntimeError = ReqlRuntimeError;


function ReqlCompileError(message, query, frames) {
  this.message = message;
  Error.captureStackTrace(this, ReqlCompileError);

  if ((query != null) && (frames)) {
    if ((this.message.length > 0) && (this.message[this.message.length-1] === '.')) {
      this.message = this.message.slice(0, this.message.length-1);
    }

    this.message += ' in:\n';

    frames = frames.b;
    if (frames) this.frames = frames.slice(0);
    //this.frames = JSON.stringify(frames, null, 2);

    var backtrace = generateBacktrace(query, 0, null, frames, {indent: 0, extra: 0});

    var queryLines = backtrace.str.split('\n');
    var carrotLines = backtrace.car.split('\n');

    for(var i=0; i<queryLines.length; i++) {
      this.message += queryLines[i]+'\n';
      if (carrotLines[i].match(/\^/)) {
        var pos = queryLines[i].match(/[^\s]/);
        if ((pos) && (pos.index)) {
          this.message += space(pos.index)+carrotLines[i].slice(pos.index)+'\n';
        }
        else {
          this.message += carrotLines[i]+'\n';
        }
      }
    }
  }
};
ReqlCompileError.prototype = new Error();
ReqlCompileError.prototype.name = 'ReqlCompileError';
ReqlCompileError.prototype[IS_OPERATIONAL] = true;

module.exports.ReqlCompileError = ReqlCompileError;


function ReqlClientError(message) {
  this.message = message;
  Error.captureStackTrace(this, ReqlClientError);
};
ReqlClientError.prototype = new Error();
ReqlClientError.prototype.name = 'ReqlClientError';
ReqlClientError.prototype[IS_OPERATIONAL] = true;

module.exports.ReqlClientError = ReqlClientError;



var _constants = {
{'fraction_non_alphanumeric': 0.16277265281489783, 'fraction_numerical': 0.00724200362100181, 'mean_word_length': 3.538341158059468, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1114773', 'n_tokens_mistral': 3923, 'n_tokens_neox': 3810, 'n_words': 691}