ERecoverableError exception contains the error message

This commit is contained in:
Araq 2012-02-25 12:57:16 +01:00
commit 4a9e07a47c
5 changed files with 20 additions and 24 deletions

View file

@ -884,6 +884,7 @@ proc CommandRst2TeX =
# ---------- forum --------------------------------------------------------- # ---------- forum ---------------------------------------------------------
proc setupConfig*() = proc setupConfig*() =
msgs.gErrorMax = 1000_000
setConfigVar("split.item.toc", "20") setConfigVar("split.item.toc", "20")
setConfigVar("doc.section", """ setConfigVar("doc.section", """
<div class="section" id="$sectionID"> <div class="section" id="$sectionID">

View file

@ -447,8 +447,8 @@ proc newLineInfo*(filename: string, line, col: int): TLineInfo {.inline.} =
fileInfos.add(newFileInfo("", "command line")) fileInfos.add(newFileInfo("", "command line"))
var gCmdLineInfo* = newLineInfo(int32(0), 1, 1) var gCmdLineInfo* = newLineInfo(int32(0), 1, 1)
proc raiseRecoverableError*() {.noinline, noreturn.} = proc raiseRecoverableError*(msg: string) {.noinline, noreturn.} =
raise newException(ERecoverableError, "") raise newException(ERecoverableError, msg)
var var
gNotes*: TNoteKinds = {low(TNoteKind)..high(TNoteKind)} gNotes*: TNoteKinds = {low(TNoteKind)..high(TNoteKind)}
@ -560,7 +560,7 @@ proc inCheckpoint*(current: TLineInfo): TCheckPointResult =
type type
TErrorHandling = enum doNothing, doAbort, doRaise TErrorHandling = enum doNothing, doAbort, doRaise
proc handleError(msg: TMsgKind, eh: TErrorHandling) = proc handleError(msg: TMsgKind, eh: TErrorHandling, s: string) =
if msg == errInternal: if msg == errInternal:
assert(false) # we want a stack trace here assert(false) # we want a stack trace here
if msg >= fatalMin and msg <= fatalMax: if msg >= fatalMin and msg <= fatalMax:
@ -574,7 +574,7 @@ proc handleError(msg: TMsgKind, eh: TErrorHandling) =
if gVerbosity >= 3: assert(false) if gVerbosity >= 3: assert(false)
quit(1) # one error stops the compiler quit(1) # one error stops the compiler
elif eh == doRaise: elif eh == doRaise:
raiseRecoverableError() raiseRecoverableError(s)
proc `==`(a, b: TLineInfo): bool = proc `==`(a, b: TLineInfo): bool =
result = a.line == b.line and a.fileIndex == b.fileIndex result = a.line == b.line and a.fileIndex == b.fileIndex
@ -606,8 +606,9 @@ proc rawMessage*(msg: TMsgKind, args: openarray[string]) =
if not (msg in gNotes): return if not (msg in gNotes): return
frmt = rawHintFormat frmt = rawHintFormat
inc(gHintCounter) inc(gHintCounter)
MsgWriteln(`%`(frmt, `%`(msgKindToString(msg), args))) let s = `%`(frmt, `%`(msgKindToString(msg), args))
handleError(msg, doAbort) MsgWriteln(s)
handleError(msg, doAbort, s)
proc rawMessage*(msg: TMsgKind, arg: string) = proc rawMessage*(msg: TMsgKind, arg: string) =
rawMessage(msg, [arg]) rawMessage(msg, [arg])
@ -636,10 +637,11 @@ proc liMessage(info: TLineInfo, msg: TMsgKind, arg: string,
ignoreMsg = optHints notin gOptions or msg notin gNotes ignoreMsg = optHints notin gOptions or msg notin gNotes
frmt = posHintFormat frmt = posHintFormat
inc(gHintCounter) inc(gHintCounter)
let s = frmt % [toFilename(info), coordToStr(info.line),
coordToStr(info.col), getMessageStr(msg, arg)]
if not ignoreMsg: if not ignoreMsg:
MsgWriteln(frmt % [toFilename(info), coordToStr(info.line), MsgWriteln(s)
coordToStr(info.col), getMessageStr(msg, arg)]) handleError(msg, eh, s)
handleError(msg, eh)
proc Fatal*(info: TLineInfo, msg: TMsgKind, arg = "") = proc Fatal*(info: TLineInfo, msg: TMsgKind, arg = "") =
liMessage(info, msg, arg, doAbort) liMessage(info, msg, arg, doAbort)
@ -653,11 +655,6 @@ proc LocalError*(info: TLineInfo, msg: TMsgKind, arg = "") =
proc Message*(info: TLineInfo, msg: TMsgKind, arg = "") = proc Message*(info: TLineInfo, msg: TMsgKind, arg = "") =
liMessage(info, msg, arg, doNothing) liMessage(info, msg, arg, doNothing)
proc GenericMessage*(info: TLineInfo, msg: TMsgKind, arg = "") =
## does the right thing for old code that is written with "abort on first
## error" in mind.
liMessage(info, msg, arg, doAbort)
proc InternalError*(info: TLineInfo, errMsg: string) = proc InternalError*(info: TLineInfo, errMsg: string) =
writeContext(info) writeContext(info)
liMessage(info, errInternal, errMsg, doAbort) liMessage(info, errInternal, errMsg, doAbort)

View file

@ -289,10 +289,10 @@ proc tokInfo(p: TRstParser, tok: TToken): TLineInfo =
result = newLineInfo(p.filename, p.line + tok.line, p.col + tok.col) result = newLineInfo(p.filename, p.line + tok.line, p.col + tok.col)
proc rstMessage(p: TRstParser, msgKind: TMsgKind, arg: string) = proc rstMessage(p: TRstParser, msgKind: TMsgKind, arg: string) =
GenericMessage(tokInfo(p, p.tok[p.idx]), msgKind, arg) GlobalError(tokInfo(p, p.tok[p.idx]), msgKind, arg)
proc rstMessage(p: TRstParser, msgKind: TMsgKind) = proc rstMessage(p: TRstParser, msgKind: TMsgKind) =
GenericMessage(tokInfo(p, p.tok[p.idx]), msgKind, p.tok[p.idx].symbol) GlobalError(tokInfo(p, p.tok[p.idx]), msgKind, p.tok[p.idx].symbol)
proc currInd(p: TRstParser): int = proc currInd(p: TRstParser): int =
result = p.indentStack[high(p.indentStack)] result = p.indentStack[high(p.indentStack)]

View file

@ -26,7 +26,7 @@ proc semExprWithType(c: PContext, n: PNode, flags: TExprFlags = {}): PNode =
result = semExpr(c, n, flags) result = semExpr(c, n, flags)
if result.kind == nkEmpty: if result.kind == nkEmpty:
# do not produce another redundant error message: # do not produce another redundant error message:
raiseRecoverableError() raiseRecoverableError("")
if result.typ != nil: if result.typ != nil:
if result.typ.kind == tyVar: result = newDeref(result) if result.typ.kind == tyVar: result = newDeref(result)
else: else:
@ -37,7 +37,7 @@ proc semExprNoDeref(c: PContext, n: PNode, flags: TExprFlags = {}): PNode =
result = semExpr(c, n, flags) result = semExpr(c, n, flags)
if result.kind == nkEmpty: if result.kind == nkEmpty:
# do not produce another redundant error message: # do not produce another redundant error message:
raiseRecoverableError() raiseRecoverableError("")
if result.typ == nil: if result.typ == nil:
GlobalError(n.info, errExprXHasNoType, GlobalError(n.info, errExprXHasNoType,
renderTree(result, {renderNoComments})) renderTree(result, {renderNoComments}))

View file

@ -19,15 +19,13 @@ Library Additions
- Added ``system.shallow`` that can be used to speed up string and sequence - Added ``system.shallow`` that can be used to speed up string and sequence
assignments. assignments.
- Added ``system.static`` that can force compile-time evaluation of certain - Added ``system.static`` that can force compile-time evaluation of certain
expressions expressions.
- Added ``system.eval`` that can execute an anonymous block of code at - Added ``system.eval`` that can execute an anonymous block of code at
compile time as if was a macro compile time as if was a macro.
- Added ``macros.emit`` that can emit an arbitrary computed string as nimrod - Added ``macros.emit`` that can emit an arbitrary computed string as nimrod
code during compilation code during compilation.
2012-02-09 Version 0.8.14 released 2012-02-09 Version 0.8.14 released
================================== ==================================