Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add simple writeStackTrace for JS backend #16016

Merged
merged 3 commits into from
Nov 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
2 changes: 1 addition & 1 deletion lib/system.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions lib/system/jssys.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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
timotheecour marked this conversation as resolved.
Show resolved Hide resolved

proc getStackTrace*(): string = rawWriteStackTrace()
proc getStackTrace*(e: ref Exception): string = e.trace

Expand Down
12 changes: 12 additions & 0 deletions tests/js/twritestacktrace.nim
Original file line number Diff line number Diff line change
@@ -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()