Create a unified diff between two strings

@param {Error}  err          Error object
@param {string} err.actual   Actual result returned
@param {string} err.expected Result expected

@return {string} diff
766520
function createUnifiedDiff({ actual, expected }) {
  return diff.createPatch('string', actual, expected)
    .split('\n')
    .splice(4)
    .map(line => {
      if (line.match(/@@/)) {
        return null;
      }
      if (line.match(/\\ No newline/)) {
        return null;
      }
      return line.replace(/^(-|\+)/, '$1 ');
    })
    .filter(line => typeof line !== 'undefined' && line !== null)
    .join('\n');
}
807764
function onError(err) {
    const ctx = err.client.$ctx;
    npm.events.error(ctx.options, err, {
        cn: npm.utils.getSafeConnection(ctx.cn),
        dc: ctx.dc
    });
}
1162829
function parseError (err) {
    var filePath, lineNum, splitLines
    var result = {}

    // For root files that syntax-error doesn't pick up:
    var parseFilePrefix = 'Parsing file '
    if (err.indexOf(parseFilePrefix) === 0) {
      var pathWithErr = err.substring(parseFilePrefix.length)
      filePath = getFilePath(pathWithErr)
      if (!filePath) return result
      result.path = filePath
      var messageAndLine = pathWithErr.substring(filePath.length)
      lineNum = /\((\d+):(\d+)\)/.exec(messageAndLine)
      if (!lineNum) return result
      result.message = messageAndLine.substring(1, lineNum.index).trim()
      result.line = parseInt(lineNum[1], 10)
      result.column = parseInt(lineNum[2], 10)
      result.format = true
      return result
    }

    // if module not found
    var cannotFindModule = /^Cannot find module '(.+)' from '(.+)'(?:$| while parsing file: (.*)$)/.exec(err.trim())
    if (cannotFindModule) {
      result.missingModule = cannotFindModule[1]
      result.path = cannotFindModule[3] || cannotFindModule[2]
      result.message = "Cannot find module '" + result.missingModule + "'"
      result.format = true
      return result
    }

    // syntax-error returns the path and line number, also a \n at start
    err = err.trim()
    filePath = getFilePath(err)
    if (!filePath) return result
    result.path = filePath

    var restOfMessage = err.substring(filePath.length)
    var parsedSyntaxError = /^:(\d+)/.exec(restOfMessage)
    if (parsedSyntaxError) { // this is a syntax-error
      lineNum = parseInt(parsedSyntaxError[1], 10)
      if (isFinite(lineNum)) result.line = lineNum
      splitLines = restOfMessage.split('\n')
      var code = splitLines.slice(1, splitLines.length - 1).join('\n')
      result.code = code
      result.message = splitLines[splitLines.length - 1]
      result.format = true
      return result
    }

    // remove colon
    restOfMessage = restOfMessage.substring(1).trim()
    var whileParsing = 'while parsing file: '
    var whileParsingIdx = restOfMessage.indexOf(whileParsing)
    if (whileParsingIdx >= 0) {
      var beforeWhile = restOfMessage.substring(0, whileParsingIdx)
      lineNum = /\((\d+):(\d+)\)/.exec(beforeWhile.split('\n')[0])
      var messageStr = beforeWhile
      if (lineNum) {
        var line = parseInt(lineNum[1], 10)
        var col = parseInt(lineNum[2], 10)
        if (isFinite(line)) result.line = line
        if (isFinite(col)) result.column = col
        messageStr = messageStr.substring(0, lineNum.index)
      }
      result.message = messageStr.trim()
      splitLines = restOfMessage.split('\n')
      result.code = splitLines.slice(2).join('\n')
      result.format = true
    }

    return result
  }
605692
function(err) {
    var errToStr = function(err) {
        var obj = {};
        Object.getOwnPropertyNames(err)
            .forEach(function(key) { obj[key] = err[key]; });
        return JSON.stringify(obj, null, 2);
    };

    var result = errToStr(err);
    if (typeof result === 'string') {
        result = result.replace(/\\n/g, '\n');
    }
    return result;
}
1102454
function errorDiff(actual, expected) {
  return diff
    .diffWordsWithSpace(actual, expected)
    .map(function(str) {
      if (str.added) {
        return colorLines('diff added', str.value);
      }
      if (str.removed) {
        return colorLines('diff removed', str.value);
      }
      return str.value;
    })
    .join('');
}
549773
func (e Errors) Err() error {
	if len(e) == 0 {
		return nil
	}

	return &MultiError{Errors: e}
}
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;
    }
215910
function onError(err) {
    if (!retries.length) return reject(err);
    setTimeout(()=>fn().then(resolve, onError), retries.shift());
  }
1238592
function formatError(err, input) {
    var msg = err.message.replace(/\s*\(\d*\:\d*\)\s*$/i, ''); // remove line number / col number

    var bm = ('' + input.slice(0, err.pos)).match(/.*$/i);
    var am = ('' + input.slice(err.pos)).match(/.*/i);
    var before = bm ? bm[0] : '';
    var after = am ? am[0] : '';

    // Prepare line info for txt display
    var cursorPos = before.length;
    var lineStr = before + after;
    var lncursor = [];
    for (var i = 0, sz = lineStr.length; sz > i; i++) {
        lncursor[i] = (i === cursorPos) ? '\u005E' : '-';
    }
    var lineInfoTxt = lineStr + '\n' + lncursor.join('');

    return {
        description: msg,
        lineInfoTxt: lineInfoTxt,
        code: lineStr,
        line: err.loc ? err.loc.line : -1,
        column: err.loc ? err.loc.column : -1
    };
}
1067197
function __err2code(program, err) {
            if (typeof err.stack !== 'string')
                return indent(program, 4);
            var match = /<anonymous>:(\d+):(\d+)\)/.exec(err.stack);
            if (!match) {
                return indent(program, 4);
            }
            var line = parseInt(match[1], 10)-1,
                start = line - 3,
                end = line + 4,
                lines = program.split("\n");
            if (start < 0) start = 0;
            if (end > lines.length) end = lines.length;
            var code = [];
            start = 0; end = lines.length;
            while (start < end) {
                code.push(start === line ? "--> "+lines[start] : "    "+lines[start]);
                start++;
            }
            return indent(code.join('\n'), 4);
        }
1164533
function formatError(err, options) {
    options = options || {};
    var name = err.name || err.constructor.name;
    var str = util.format('%s: %s\n', name, err.message);
    if (err.buffer && err.buffer.hexdump) {
        str += err.buffer.hexdump({
            colored: options.color,
            boldStart: false,
            highlight: options.color ? errorHighlighter(err, options) : null
        });
    } else if (Buffer.isBuffer(err.buffer)) {
        if (options.color) {
            str += formatBufferColored(err, options);
        } else {
            str += formatBufferUncolored(err, options);
        }
    }
    return str;
}
9553
def make_err(self, errtype, message, original, loc, ln=None, reformat=True, *args, **kwargs):
        """"""
        if ln is None:
            ln = self.adjust(lineno(loc, original))
        errstr, index = getline(loc, original), col(loc, original) - 1
        if reformat:
            errstr, index = self.reformat(errstr, index)
        return errtype(message, errstr, index, ln, *args, **kwargs)
800050
function getDiffForPR(pr) {
  print(['Get diff for PR ', clc.yellow.bold(`${pr.head.user.login}/${pr.head.repo.name}#${pr.number}`)], debug);
  return new Promise((resolve) => {
    github.repos.compareCommits({
      user: pr.head.user.login,
      repo: pr.head.repo.name,
      head: pr.head.ref,
      base: pr.base.ref
    }, (err, diff) => {
      if (err && debug) {
        print(['Error fetching diffs for PR ', clc.red.bold`${pr.head.user.login}/${pr.head.repo.name}#${pr.number}`], debug);
      }
      diff.user = pr.head.user.login;
      diff.repo = pr.head.repo.name;
      diff.title = pr.title;
      diff.number = pr.number;
      diff.link = pr._links.html.href;
      diff.createdAt = pr.created_at;
      diff.createdAt = pr.updated_at;
      diff.labels = pr.labels;
      return resolve(extractDiffData(diff));
    });
  });
}
838489
def make_parse_err(self, err, reformat=True, include_ln=True):
        """"""
        err_line = err.line
        err_index = err.col - 1
        err_lineno = err.lineno if include_ln else None
        if reformat:
            err_line, err_index = self.reformat(err_line, err_index)
            if err_lineno is not None:
                err_lineno = self.adjust(err_lineno)
        return CoconutParseError(None, err_line, err_index, err_lineno)
935086
function(err) {
        if (err) { done(err); return; }
        var assert = require('assert');
        var difflet = require('difflet')({indent: 2, comment: true});
        try {
          assert.deepEqual(options.test.actual, options.expected, 'Actual should match expected.');
          grunt.log.writeln('Test passed.');
          done();
        } catch (err) {
          grunt.log.subhead('Assertion Failure');
          console.log(difflet.compare(err.expected, err.actual));
          done(err);
        }
      }
1246979
func (parser *Parser) err() error {
	if parser.tokenError() {
		token := parser.nextToken()
		return fmt.Errorf("Tokenizer error: %s", token.String())
	}

	return nil
}
442313
function(err, data) {
        var regexp = RegExp(/(Z\d)ON/);
        var ret;

        if (data) {
            for (i = 0; i < data.length; i++) {
                if (ret = regexp.exec(data[i])) {
                    zones[ret[1]] = ret[1];
                } else if (data[i] == 'PWON') {
                    zones['ZM'] = 'ZM';
                }
            }
        }
        mdt.telnet('RR?', handleZoneNames);
    }