mirror of
https://github.com/nim-lang/Nim.git
synced 2026-07-19 15:31:28 +00:00
@@ -27,7 +27,10 @@ proc createDocLink*(urlSuffix: string): string =
|
||||
|
||||
type
|
||||
TMsgKind* = enum
|
||||
errUnknown, errInternal, errIllFormedAstX, errCannotOpenFile,
|
||||
# fatal errors
|
||||
errUnknown, errFatal, errInternal,
|
||||
# non-fatal errors
|
||||
errIllFormedAstX, errCannotOpenFile,
|
||||
errXExpected,
|
||||
errGridTableNotImplemented,
|
||||
errMarkdownIllformedTable,
|
||||
@@ -38,7 +41,7 @@ type
|
||||
errProveInit, # deadcode
|
||||
errGenerated,
|
||||
errUser,
|
||||
|
||||
# warnings
|
||||
warnCannotOpenFile = "CannotOpenFile", warnOctalEscape = "OctalEscape",
|
||||
warnXIsNeverRead = "XIsNeverRead", warnXmightNotBeenInit = "XmightNotBeenInit",
|
||||
warnDeprecated = "Deprecated", warnConfigDeprecated = "ConfigDeprecated",
|
||||
@@ -64,7 +67,7 @@ type
|
||||
warnCannotOpen = "CannotOpen",
|
||||
warnFileChanged = "FileChanged",
|
||||
warnUser = "User",
|
||||
|
||||
# hints
|
||||
hintSuccess = "Success", hintSuccessX = "SuccessX",
|
||||
hintCC = "CC",
|
||||
hintLineTooLong = "LineTooLong", hintXDeclaredButNotUsed = "XDeclaredButNotUsed",
|
||||
@@ -83,6 +86,7 @@ type
|
||||
const
|
||||
MsgKindToStr*: array[TMsgKind, string] = [
|
||||
errUnknown: "unknown error",
|
||||
errFatal: "fatal error: $1",
|
||||
errInternal: "internal error: $1",
|
||||
errIllFormedAstX: "illformed AST: $1",
|
||||
errCannotOpenFile: "cannot open '$1'",
|
||||
@@ -180,8 +184,7 @@ const
|
||||
]
|
||||
|
||||
const
|
||||
fatalMin* = errUnknown
|
||||
fatalMax* = errInternal
|
||||
fatalMsgs* = {errUnknown..errInternal}
|
||||
errMin* = errUnknown
|
||||
errMax* = errUser
|
||||
warnMin* = warnCannotOpenFile
|
||||
|
||||
@@ -153,8 +153,7 @@ proc compileSystemModule*(graph: ModuleGraph) =
|
||||
|
||||
proc wantMainModule*(conf: ConfigRef) =
|
||||
if conf.projectFull.isEmpty:
|
||||
fatal(conf, newLineInfo(conf, AbsoluteFile(commandLineDesc), 1, 1), errGenerated,
|
||||
"command expects a filename")
|
||||
fatal(conf, gCmdLineInfo, "command expects a filename")
|
||||
conf.projectMainIdx = fileInfoIdx(conf, addFileExt(conf.projectFull, NimExt))
|
||||
|
||||
proc compileProject*(graph: ModuleGraph; projectFileIdx = InvalidFileIdx) =
|
||||
|
||||
@@ -408,7 +408,7 @@ To create a stacktrace, rerun compilation with './koch temp $1 <file>', see $2 f
|
||||
quit 1
|
||||
|
||||
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)
|
||||
quit(conf, msg)
|
||||
if msg >= errMin and msg <= errMax or
|
||||
@@ -498,6 +498,12 @@ proc liMessage*(conf: ConfigRef; info: TLineInfo, msg: TMsgKind, arg: string,
|
||||
color: ForegroundColor
|
||||
ignoreMsg = false
|
||||
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
|
||||
case msg
|
||||
of errMin..errMax:
|
||||
@@ -553,6 +559,9 @@ proc liMessage*(conf: ConfigRef; info: TLineInfo, msg: TMsgKind, arg: string,
|
||||
KindFormat % $hintMsgOrigin,
|
||||
resetStyle, conf.unitSep)
|
||||
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]) =
|
||||
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) =
|
||||
liMessage(conf, unknownLineInfo, msg, arg, eh = doAbort, instLoc())
|
||||
|
||||
template fatal*(conf: ConfigRef; info: TLineInfo, msg: TMsgKind, arg = "") =
|
||||
# this fixes bug #7080 so that it is at least obvious 'fatal' was executed.
|
||||
conf.m.errorOutputs = {eStdOut, eStdErr}
|
||||
template fatal*(conf: ConfigRef; info: TLineInfo, arg = "", msg = errFatal) =
|
||||
liMessage(conf, info, msg, arg, doAbort, instLoc())
|
||||
|
||||
template globalAssert*(conf: ConfigRef; cond: untyped, info: TLineInfo = unknownLineInfo, arg = "") =
|
||||
|
||||
@@ -1047,7 +1047,7 @@ proc singlePragma(c: PContext, sym: PSym, n: PNode, i: var int,
|
||||
let s = expectStrLit(c, it)
|
||||
recordPragma(c, it, "error", 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 wUndef: processUndef(c, it)
|
||||
of wCompile: processCompile(c, it)
|
||||
|
||||
Reference in New Issue
Block a user