refs #18278: do not gag fatal msgs (#18290)

This commit is contained in:
Timothee Cour 2021-06-18 10:23:27 -07:00 • committed by GitHub
commit 5d15bd7b61
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 21 additions and 12 deletions

View file

@ -27,7 +27,10 @@ proc createDocLink*(urlSuffix: string): string =
type type
TMsgKind* = enum TMsgKind* = enum
errUnknown, errInternal, errIllFormedAstX, errCannotOpenFile, # fatal errors
errUnknown, errFatal, errInternal,
# non-fatal errors
errIllFormedAstX, errCannotOpenFile,
errXExpected, errXExpected,
errGridTableNotImplemented, errGridTableNotImplemented,
errMarkdownIllformedTable, errMarkdownIllformedTable,
@ -38,7 +41,7 @@ type
errProveInit, # deadcode errProveInit, # deadcode
errGenerated, errGenerated,
errUser, errUser,
# warnings
warnCannotOpenFile = "CannotOpenFile", warnOctalEscape = "OctalEscape", warnCannotOpenFile = "CannotOpenFile", warnOctalEscape = "OctalEscape",
warnXIsNeverRead = "XIsNeverRead", warnXmightNotBeenInit = "XmightNotBeenInit", warnXIsNeverRead = "XIsNeverRead", warnXmightNotBeenInit = "XmightNotBeenInit",
warnDeprecated = "Deprecated", warnConfigDeprecated = "ConfigDeprecated", warnDeprecated = "Deprecated", warnConfigDeprecated = "ConfigDeprecated",
@ -64,7 +67,7 @@ type
warnCannotOpen = "CannotOpen", warnCannotOpen = "CannotOpen",
warnFileChanged = "FileChanged", warnFileChanged = "FileChanged",
warnUser = "User", warnUser = "User",
# hints
hintSuccess = "Success", hintSuccessX = "SuccessX", hintSuccess = "Success", hintSuccessX = "SuccessX",
hintCC = "CC", hintCC = "CC",
hintLineTooLong = "LineTooLong", hintXDeclaredButNotUsed = "XDeclaredButNotUsed", hintLineTooLong = "LineTooLong", hintXDeclaredButNotUsed = "XDeclaredButNotUsed",
@ -83,6 +86,7 @@ type
const const
MsgKindToStr*: array[TMsgKind, string] = [ MsgKindToStr*: array[TMsgKind, string] = [
errUnknown: "unknown error", errUnknown: "unknown error",
errFatal: "fatal error: $1",
errInternal: "internal error: $1", errInternal: "internal error: $1",
errIllFormedAstX: "illformed AST: $1", errIllFormedAstX: "illformed AST: $1",
errCannotOpenFile: "cannot open '$1'", errCannotOpenFile: "cannot open '$1'",
@ -180,8 +184,7 @@ const
] ]
const const
fatalMin* = errUnknown fatalMsgs* = {errUnknown..errInternal}
fatalMax* = errInternal
errMin* = errUnknown errMin* = errUnknown
errMax* = errUser errMax* = errUser
warnMin* = warnCannotOpenFile warnMin* = warnCannotOpenFile

View file

@ -153,8 +153,7 @@ proc compileSystemModule*(graph: ModuleGraph) =
proc wantMainModule*(conf: ConfigRef) = proc wantMainModule*(conf: ConfigRef) =
if conf.projectFull.isEmpty: if conf.projectFull.isEmpty:
fatal(conf, newLineInfo(conf, AbsoluteFile(commandLineDesc), 1, 1), errGenerated, fatal(conf, gCmdLineInfo, "command expects a filename")
"command expects a filename")
conf.projectMainIdx = fileInfoIdx(conf, addFileExt(conf.projectFull, NimExt)) conf.projectMainIdx = fileInfoIdx(conf, addFileExt(conf.projectFull, NimExt))
proc compileProject*(graph: ModuleGraph; projectFileIdx = InvalidFileIdx) = proc compileProject*(graph: ModuleGraph; projectFileIdx = InvalidFileIdx) =

View file

@ -408,7 +408,7 @@ To create a stacktrace, rerun compilation with './koch temp $1 <file>', see $2 f
quit 1 quit 1
proc handleError(conf: ConfigRef; msg: TMsgKind, eh: TErrorHandling, s: string) = proc handleError(conf: ConfigRef; msg: TMsgKind, eh: TErrorHandling, s: string) =
if msg >= fatalMin and msg <= fatalMax: if msg in fatalMsgs:
if conf.cmd == cmdIdeTools: log(s) if conf.cmd == cmdIdeTools: log(s)
quit(conf, msg) quit(conf, msg)
if msg >= errMin and msg <= errMax or if msg >= errMin and msg <= errMax or
@ -498,6 +498,12 @@ proc liMessage*(conf: ConfigRef; info: TLineInfo, msg: TMsgKind, arg: string,
color: ForegroundColor color: ForegroundColor
ignoreMsg = false ignoreMsg = false
sev: Severity sev: Severity
let errorOutputsOld = conf.m.errorOutputs
if msg in fatalMsgs:
# don't gag, refs bug #7080, bug #18278; this can happen with `{.fatal.}`
# or inside a `tryConstExpr`.
conf.m.errorOutputs = {eStdOut, eStdErr}
let kind = if msg in warnMin..hintMax and msg != hintUserRaw: $msg else: "" # xxx not sure why hintUserRaw is special let kind = if msg in warnMin..hintMax and msg != hintUserRaw: $msg else: "" # xxx not sure why hintUserRaw is special
case msg case msg
of errMin..errMax: of errMin..errMax:
@ -553,6 +559,9 @@ proc liMessage*(conf: ConfigRef; info: TLineInfo, msg: TMsgKind, arg: string,
KindFormat % $hintMsgOrigin, KindFormat % $hintMsgOrigin,
resetStyle, conf.unitSep) resetStyle, conf.unitSep)
handleError(conf, msg, eh, s) handleError(conf, msg, eh, s)
if msg in fatalMsgs:
# most likely would have died here but just in case, we restore state
conf.m.errorOutputs = errorOutputsOld
template rawMessage*(conf: ConfigRef; msg: TMsgKind, args: openArray[string]) = template rawMessage*(conf: ConfigRef; msg: TMsgKind, args: openArray[string]) =
let arg = msgKindToString(msg) % args let arg = msgKindToString(msg) % args
@ -561,9 +570,7 @@ template rawMessage*(conf: ConfigRef; msg: TMsgKind, args: openArray[string]) =
template rawMessage*(conf: ConfigRef; msg: TMsgKind, arg: string) = template rawMessage*(conf: ConfigRef; msg: TMsgKind, arg: string) =
liMessage(conf, unknownLineInfo, msg, arg, eh = doAbort, instLoc()) liMessage(conf, unknownLineInfo, msg, arg, eh = doAbort, instLoc())
template fatal*(conf: ConfigRef; info: TLineInfo, msg: TMsgKind, arg = "") = template fatal*(conf: ConfigRef; info: TLineInfo, arg = "", msg = errFatal) =
# this fixes bug #7080 so that it is at least obvious 'fatal' was executed.
conf.m.errorOutputs = {eStdOut, eStdErr}
liMessage(conf, info, msg, arg, doAbort, instLoc()) liMessage(conf, info, msg, arg, doAbort, instLoc())
template globalAssert*(conf: ConfigRef; cond: untyped, info: TLineInfo = unknownLineInfo, arg = "") = template globalAssert*(conf: ConfigRef; cond: untyped, info: TLineInfo = unknownLineInfo, arg = "") =

View file

@ -1047,7 +1047,7 @@ proc singlePragma(c: PContext, sym: PSym, n: PNode, i: var int,
let s = expectStrLit(c, it) let s = expectStrLit(c, it)
recordPragma(c, it, "error", s) recordPragma(c, it, "error", s)
localError(c.config, it.info, errUser, s) localError(c.config, it.info, errUser, s)
of wFatal: fatal(c.config, it.info, errUser, expectStrLit(c, it)) of wFatal: fatal(c.config, it.info, expectStrLit(c, it))
of wDefine: processDefine(c, it) of wDefine: processDefine(c, it)
of wUndef: processUndef(c, it) of wUndef: processUndef(c, it)
of wCompile: processCompile(c, it) of wCompile: processCompile(c, it)