From 4db3b67fbf96d97cbd01f714a9f615427e7dc838 Mon Sep 17 00:00:00 2001 From: thindil Date: Sat, 4 Nov 2023 06:07:27 +0000 Subject: [PATCH] feat: added logging the shell's errors in debug mode FossilOrigin-Name: 57a086036839b916595610adbdbea52423f7edf99fd29e07d7359a30f0031652 --- src/output.nim | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/output.nim b/src/output.nim index 3ffba27d..b2ef0112 100644 --- a/src/output.nim +++ b/src/output.nim @@ -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 @@ -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. @@ -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: