From a2304ec7ef01992d8620fef2bcc2efcead6d1bf6 Mon Sep 17 00:00:00 2001 From: flywind Date: Tue, 17 Nov 2020 18:08:39 +0800 Subject: [PATCH 1/3] add simple writeStackTrace for JS backend --- lib/system.nim | 2 +- lib/system/jssys.nim | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/system.nim b/lib/system.nim index e41dfe1ca9f31..ab9140c13768b 100644 --- a/lib/system.nim +++ b/lib/system.nim @@ -1762,7 +1762,7 @@ when notJSnotNims and defined(nimSeqsV2): {.pop.} -when notJSnotNims: +when not defined(nimscript): proc writeStackTrace*() {.tags: [], gcsafe, raises: [].} ## Writes the current stack trace to ``stderr``. This is only works ## for debug builds. Since it's usually used for debugging, this diff --git a/lib/system/jssys.nim b/lib/system/jssys.nim index df05a9a62830c..d0be35dd097a5 100644 --- a/lib/system/jssys.nim +++ b/lib/system/jssys.nim @@ -105,6 +105,11 @@ proc rawWriteStackTrace(): string = else: result = "No stack traceback available\n" +proc writeStackTrace() = + var trace = rawWriteStackTrace() + trace.setLen(trace.len - 1) + echo trace + proc getStackTrace*(): string = rawWriteStackTrace() proc getStackTrace*(e: ref Exception): string = e.trace From 30c6acabecbdc9f49ca3a9ff77793c73f6e52738 Mon Sep 17 00:00:00 2001 From: flywind Date: Tue, 17 Nov 2020 21:09:40 +0800 Subject: [PATCH 2/3] add testcase for writeStackTrace --- tests/js/twritestacktrace.nim | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 tests/js/twritestacktrace.nim diff --git a/tests/js/twritestacktrace.nim b/tests/js/twritestacktrace.nim new file mode 100644 index 0000000000000..2fe2b1987a7e5 --- /dev/null +++ b/tests/js/twritestacktrace.nim @@ -0,0 +1,12 @@ +discard """ + cmd: "nim js --panics:on $file" + output: '''Traceback (most recent call last) +twritestacktrace.nim(12) at module twritestacktrace +twritestacktrace.nim(10) at twritestacktrace.hello +''' +""" + +proc hello() = + writeStackTrace() + +hello() From fb2f2ffd467959d19460ef4fd969a97207adbc72 Mon Sep 17 00:00:00 2001 From: flywind Date: Tue, 17 Nov 2020 21:10:30 +0800 Subject: [PATCH 3/3] changelog --- changelog.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/changelog.md b/changelog.md index d28edd34cded1..c5d65b50e6e2d 100644 --- a/changelog.md +++ b/changelog.md @@ -19,6 +19,8 @@ - Added std/enumutils module containing `genEnumCaseStmt` macro that generates case statement to parse string to enum. +- `writeStackTrace` is available in JS backend now. + ## Language changes