allow echoing internal stacktrace if compiling with `d:debug`

`internalError` and `yAssert` now allow to echo the internal stack
traces if the `d:debug` compile flag is set.
This commit is contained in:
Vindaar 2018-10-09 18:25:55 +02:00 committed by flyx
parent f0eeece22d
commit db1a2c4041
2 changed files with 17 additions and 2 deletions

View File

@ -44,6 +44,8 @@ nim build # build a library
NimYAML needs at least Nim 0.17.0 in order to compile. Version 0.9.1
is the last release to support 0.15.x and 0.16.0.
When debugging crashes in this library, use the `d:debug` compile flag to enable printing of the internal stack traces for calls to `internalError` and `yAssert`.
## License
[MIT][2]

View File

@ -5,16 +5,24 @@
# distribution, for details about the copyright.
template internalError*(s: string) =
# Note: to get the internal stacktrace that caused the error
# compile with the `d:debug` flag.
when not defined(release):
let ii = instantiationInfo()
echo "[NimYAML] Error in file ", ii.filename, " at line ", ii.line, ":"
echo s
when not defined(JS):
echo "[NimYAML] Stacktrace:"
try: writeStackTrace()
try:
writeStackTrace()
when defined(debug):
echo "Internal stacktrace:"
let exc = getCurrentException()
echo getStackTrace(exc.parent)
except: discard
echo "[NimYAML] Please report this bug."
quit 1
template yAssert*(e: typed) =
when not defined(release):
if not e:
@ -23,7 +31,12 @@ template yAssert*(e: typed) =
echo "assertion failed!"
when not defined(JS):
echo "[NimYAML] Stacktrace:"
try: writeStackTrace()
try:
writeStackTrace()
when defined(debug):
echo "Internal stacktrace:"
let exc = getCurrentException()
echo getStackTrace(exc.parent)
except: discard
echo "[NimYAML] Please report this bug."
quit 1