message: Add surrounding source truncation for long lines
diff: @@ -162,6 +162,30 @@ function readSourceFiles(filenames, cb) {
  });
  }
  +// This is basically just `trim_line` from https://github.com/getsentry/sentry/blob/master/src/sentry/lang/javascript/processor.py#L67
  +function snipLine(line, colno) {
  + var ll = line.length;
  + if (ll <= 150) return line;
  + if (colno > ll) colno = ll;
  +
  + var start = Math.max(colno - 60, 0);
  + if (start < 5) start = 0;
  +
  + var end = Math.min(start + 140, ll);
  + if (end > ll - 5) end = ll;
  + if (end === ll) start = Math.max(end - 140, 0);
  +
  + line = line.slice(start, end);
  + if (start > 0) line = '{snip} ' + line;
  + if (end < ll) line += ' {snip}';
  +
  + return line;
  +}
  +
  +function snipLine0(line) {
  + return snipLine(line, 0);
  +}
  +
  function parseStack(err, cb) {
  if (!err) return cb([]);
  @@ -208,9 +232,9 @@ function parseStack(err, cb) {
  if (frame.filename && sourceFiles[frame.filename]) {
  var lines = sourceFiles[frame.filename];
  try {
  - frame.pre_context = lines.slice(Math.max(0, frame.lineno - (LINES_OF_CONTEXT + 1)), frame.lineno - 1);
  - frame.context_line = lines[frame.lineno - 1];
  - frame.post_context = lines.slice(frame.lineno, frame.lineno + LINES_OF_CONTEXT);
  + frame.pre_context = lines.slice(Math.max(0, frame.lineno - (LINES_OF_CONTEXT + 1)), frame.lineno - 1).map(snipLine0);
  + frame.context_line = snipLine(lines[frame.lineno - 1], frame.colno);
  + frame.post_context = lines.slice(frame.lineno, frame.lineno + LINES_OF_CONTEXT).map(snipLine0);
  } catch (e) {
  // anomaly, being defensive in case
  // unlikely to ever happen in practice but can definitely happen in theory
  