lib/error-handler.js
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
  }
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
  }
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 }
parse an error message into pieces
parse an error message into pieces