<commit_before>/* safe.js - Building a safer world for Pebble.JS Developers
 *
 * This library provides wrapper around all the asynchronous handlers that developers
 * have access to so that error messages are caught and displayed nicely in the pebble tool
 * console.
 */

var ajax = require('lib/ajax');

/* We use this function to dump error messages to the console. */
function dumpError(err) {
  if (typeof err === 'object') {
    if (err.message) {
      console.log('Message: ' + err.message);
    }
    if (err.stack) {
      console.log('Stacktrace:');
      console.log(err.stack);
    }
  } else {
    console.log('dumpError :: argument is not an object');
  }
}

/* Takes a function and return a new function with a call to it wrapped in a try/catch statement */
function protect(fn) {<commit_msg>Add safe.js filename stracetrace line translation using loader.js<commit_after>/* safe.js - Building a safer world for Pebble.JS Developers
 *
 * This library provides wrapper around all the asynchronous handlers that developers
 * have access to so that error messages are caught and displayed nicely in the pebble tool
 * console.
 */

var ajax = require('lib/ajax');

/* The name of the concatenated file to translate */
var translateName = 'pebble-js-app.js';

/* Translates a line of the stack trace to the originating file */
function translateLine(line, scope, name, lineno, colno) {
  if (name === translateName) {
    var pkg = __loader.getPackageByLineno(lineno);
    if (pkg) {
      name = pkg.filename;
      lineno -= pkg.lineno;
    }
  }
  return (scope || '') + name + ':' + lineno + ':' + colno;
}

/* Matches (<scope> '@' )? <name> ':' <lineno> ':' <colno> */
var stackLineRegExp = /([^\s@]+@)?([^\s@:]+):(\d+):(\d+)/;

/* Translates a stack trace to the originating files */
function translateStack(stack) {
  var lines = stack.split('\n');
  for (var i = lines.length - 1; i >= 0; --i) {
    var line = lines[i];
    var m = line.match(stackLineRegExp);
    if (m) {
      line = lines[i] = translateLine.apply(this, m);
    }
    if (line.match(module.filename)) {
      lines.splice(--i, 2);
    }
  }
  return lines.join('\n');
}

/* We use this function to dump error messages to the console. */
function dumpError(err) {
  if (typeof err === 'object') {
    if (err.message) {
      console.log('Message: ' + err.message);
    }
    if (err.stack) {
      console.log('Stacktrace:');
      console.log(translateStack(err.stack));
    }
  } else {
    console.log('dumpError :: argument is not an object');
  }
}

/* Takes a function and return a new function with a call to it wrapped in a try/catch statement */
function protect(fn) {
{'fraction_non_alphanumeric': 0.14082397003745317, 'fraction_numerical': 0.0011235955056179776, 'mean_word_length': 3.1410852713178294, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3054353', 'n_tokens_mistral': 846, 'n_tokens_neox': 824, 'n_words': 283}