Skip to content

Commit

Permalink
feat: added logging the shell's errors in debug mode
Browse files Browse the repository at this point in the history
FossilOrigin-Name: 57a086036839b916595610adbdbea52423f7edf99fd29e07d7359a30f0031652
  • Loading branch information
thindil committed Nov 4, 2023
1 parent 13d3463 commit 4db3b67
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/output.nim
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import std/[strutils, terminal]
import contracts, nancy, nimalyzer, termstyle
import norm/sqlite
# Internal imports
import constants, resultcode
import constants, logger, resultcode

type OutputMessage* = string
## Used to store message to show to the user
Expand Down Expand Up @@ -75,9 +75,8 @@ proc showOutput*(message; newLine: bool = true;
discard
stdout.flushFile

proc showError*(message: OutputMessage; e: ref Exception = nil): ResultCode {.gcsafe,
sideEffect, raises: [], tags: [WriteIOEffect, RootEffect], discardable,
contractual.} =
proc showError*(message: OutputMessage; e: ref Exception = nil): ResultCode {.sideEffect,
raises: [], tags: [WriteIOEffect, RootEffect], discardable, contractual.} =
## Print the message to standard error and set the shell return
## code to error. If parameter e is also supplied, it show stack trace for
## the current exception in debug mode.
Expand All @@ -103,9 +102,12 @@ proc showError*(message: OutputMessage; e: ref Exception = nil): ResultCode {.gc
else:
{.ruleOff: "namedParams".}
stderr.styledWriteLine(fgRed, $e.name)
log(message = $e.name)
stderr.styledWriteLine(fgRed, getCurrentExceptionMsg())
log(message = getCurrentExceptionMsg())
when defined(debug):
stderr.styledWrite(fgRed, getStackTrace(e = e))
stderr.styledWrite(fgRed, e.getStackTrace)
log(message = e.getStackTrace)
{.ruleOn: "namedParams".}
except IOError, ValueError:
try:
Expand Down

0 comments on commit 4db3b67

Please sign in to comment.