mirror of https://github.com/status-im/NimYAML.git
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:
parent
f0eeece22d
commit
db1a2c4041
|
@ -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
|
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.
|
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
|
## License
|
||||||
|
|
||||||
[MIT][2]
|
[MIT][2]
|
||||||
|
|
|
@ -5,16 +5,24 @@
|
||||||
# distribution, for details about the copyright.
|
# distribution, for details about the copyright.
|
||||||
|
|
||||||
template internalError*(s: string) =
|
template internalError*(s: string) =
|
||||||
|
# Note: to get the internal stacktrace that caused the error
|
||||||
|
# compile with the `d:debug` flag.
|
||||||
when not defined(release):
|
when not defined(release):
|
||||||
let ii = instantiationInfo()
|
let ii = instantiationInfo()
|
||||||
echo "[NimYAML] Error in file ", ii.filename, " at line ", ii.line, ":"
|
echo "[NimYAML] Error in file ", ii.filename, " at line ", ii.line, ":"
|
||||||
echo s
|
echo s
|
||||||
when not defined(JS):
|
when not defined(JS):
|
||||||
echo "[NimYAML] Stacktrace:"
|
echo "[NimYAML] Stacktrace:"
|
||||||
try: writeStackTrace()
|
try:
|
||||||
|
writeStackTrace()
|
||||||
|
when defined(debug):
|
||||||
|
echo "Internal stacktrace:"
|
||||||
|
let exc = getCurrentException()
|
||||||
|
echo getStackTrace(exc.parent)
|
||||||
except: discard
|
except: discard
|
||||||
echo "[NimYAML] Please report this bug."
|
echo "[NimYAML] Please report this bug."
|
||||||
quit 1
|
quit 1
|
||||||
|
|
||||||
template yAssert*(e: typed) =
|
template yAssert*(e: typed) =
|
||||||
when not defined(release):
|
when not defined(release):
|
||||||
if not e:
|
if not e:
|
||||||
|
@ -23,7 +31,12 @@ template yAssert*(e: typed) =
|
||||||
echo "assertion failed!"
|
echo "assertion failed!"
|
||||||
when not defined(JS):
|
when not defined(JS):
|
||||||
echo "[NimYAML] Stacktrace:"
|
echo "[NimYAML] Stacktrace:"
|
||||||
try: writeStackTrace()
|
try:
|
||||||
|
writeStackTrace()
|
||||||
|
when defined(debug):
|
||||||
|
echo "Internal stacktrace:"
|
||||||
|
let exc = getCurrentException()
|
||||||
|
echo getStackTrace(exc.parent)
|
||||||
except: discard
|
except: discard
|
||||||
echo "[NimYAML] Please report this bug."
|
echo "[NimYAML] Please report this bug."
|
||||||
quit 1
|
quit 1
|
||||||
|
|
Loading…
Reference in New Issue