Exemple #1
0
    def MaybeCollect(self, ex, err):
        # type: (Any, _ErrorWithLocation) -> None
        # TODO: Any -> Executor
        """
    Args:
      ex: Executor instance
      error: _ErrorWithLocation (ParseError or FatalRuntimeError)
    """
        if not self.do_collect:  # Either we already did it, or there is no file
            return

        self.var_stack, self.argv_stack, self.debug_stack = ex.mem.Dump()
        span_id = word.SpanIdFromError(err)

        self.error = {
            'msg': err.UserErrorString(),
            'span_id': span_id,
        }

        if span_id != const.NO_INTEGER:
            span = ex.arena.GetLineSpan(span_id)
            line_id = span.line_id

            # Could also do msg % args separately, but JavaScript won't be able to
            # render that.
            self.error['source'] = ex.arena.GetLineSourceString(line_id)
            self.error['line_num'] = ex.arena.GetLineNumber(line_id)
            self.error['line'] = ex.arena.GetLine(line_id)

        # TODO: Collect functions, aliases, etc.

        self.do_collect = False
        self.collected = True
Exemple #2
0
    def _ValToArithOrError(self,
                           val,
                           int_coerce=True,
                           blame_word=None,
                           span_id=const.NO_INTEGER):
        if span_id == const.NO_INTEGER and blame_word:
            span_id = word.LeftMostSpanForWord(blame_word)
        #log('_ValToArithOrError span=%s blame=%s', span_id, blame_word)

        try:
            i = self._ValToArith(val, span_id, int_coerce=int_coerce)
        except util.FatalRuntimeError as e:
            if self.exec_opts.strict_arith:
                raise
            else:
                i = 0

                span_id = word.SpanIdFromError(e)
                if self.arena:  # BoolEvaluator for test builtin doesn't have it.
                    if span_id != const.NO_INTEGER:
                        ui.PrintFilenameAndLine(span_id, self.arena)
                    else:
                        log('*** Warning has no location info ***')
                warn(e.UserErrorString())
        return i
Exemple #3
0
  def _ValToArithOrError(self, val, blame_word=None, span_id=const.NO_INTEGER):
    if span_id == const.NO_INTEGER and blame_word:
      span_id = word.LeftMostSpanForWord(blame_word)
    #log('_ValToArithOrError span=%s blame=%s', span_id, blame_word)

    try:
      i = self._ValToArith(val, span_id)
    except util.FatalRuntimeError as e:
      if self.exec_opts.strict_arith:
        raise
      else:
        i = 0
        span_id = word.SpanIdFromError(e)
        self.errfmt.PrettyPrintError(e, prefix='warning: ')
    return i
Exemple #4
0
  def _ValToArithOrError(self, val, int_coerce=True, blame_word=None,
                         span_id=const.NO_INTEGER):
    if span_id == const.NO_INTEGER and blame_word:
      span_id = word.LeftMostSpanForWord(blame_word)
    #log('_ValToArithOrError span=%s blame=%s', span_id, blame_word)

    try:
      i = self._ValToArith(val, span_id, int_coerce=int_coerce)
    except util.FatalRuntimeError as e:
      if self.exec_opts.strict_arith:
        raise
      else:
        i = 0
        span_id = word.SpanIdFromError(e)
        ui.PrintWarning(e.UserErrorString(), span_id, self.arena)
    return i
Exemple #5
0
Fichier : ui.py Projet : mrshu/oil
def PrettyPrintError(err, arena, prefix='', f=sys.stderr):
  # type: (_ErrorWithLocation, Arena, str, IO[str]) -> None
  """
  Args:
    prefix: in osh/cmd_exec.py we want to print 'fatal'
  """
  msg = err.UserErrorString()
  span_id = word.SpanIdFromError(err)

  # TODO: Should there be a special span_id of 0 for EOF?  const.NO_INTEGER
  # means there is no location info, but 0 could mean that the location is EOF.
  # So then you query the arena for the last line in that case?
  # Eof_Real is the ONLY token with 0 span, because it's invisible!
  # Well Eol_Tok is a sentinel with a span_id of const.NO_INTEGER.  I think
  # that is OK.
  # Problem: the column for Eof could be useful.

  _PrintWithOptionalSpanId(prefix, msg, span_id, arena, f)
Exemple #6
0
Fichier : ui.py Projet : jyn514/oil
def PrettyPrintError(err, arena, prefix='', f=sys.stderr):
    # type: (ParseError, Arena, str, IO[str]) -> None
    span_id = word.SpanIdFromError(err)

    # TODO: Should there be a special span_id of 0 for EOF?  const.NO_INTEGER
    # means there is no location info, but 0 could mean that the location is EOF.
    # So then you query the arena for the last line in that case?
    # Eof_Real is the ONLY token with 0 span, because it's invisible!
    # Well Eol_Tok is a sentinel with a span_id of const.NO_INTEGER.  I think
    # that is OK.
    # Problem: the column for Eof could be useful.

    if span_id == const.NO_INTEGER:  # Any clause above might return this.
        # This is usually a bug.
        print('*** Error has no source location info ***', file=f)
    else:
        PrintFilenameAndLine(span_id, arena, f=f)

    f.write(prefix)
    print(err.UserErrorString(), file=f)