add simple writeStackTrace for JS backend (#16016)
* add simple writeStackTrace for JS backend * add testcase for writeStackTrace * changelog
This commit is contained in:
parent
3fed85437b
commit
19e224866b
4 changed files with 20 additions and 1 deletions
|
|
@ -47,6 +47,8 @@
|
||||||
- `repr` now doesn't insert trailing newline; previous behavior was very inconsistent,
|
- `repr` now doesn't insert trailing newline; previous behavior was very inconsistent,
|
||||||
see #16034. Use `-d:nimLegacyReprWithNewline` for previous behavior.
|
see #16034. Use `-d:nimLegacyReprWithNewline` for previous behavior.
|
||||||
|
|
||||||
|
- `writeStackTrace` is available in JS backend now.
|
||||||
|
|
||||||
## Language changes
|
## Language changes
|
||||||
|
|
||||||
- `nimscript` now handles `except Exception as e`
|
- `nimscript` now handles `except Exception as e`
|
||||||
|
|
|
||||||
|
|
@ -1765,7 +1765,7 @@ when notJSnotNims and defined(nimSeqsV2):
|
||||||
|
|
||||||
{.pop.}
|
{.pop.}
|
||||||
|
|
||||||
when notJSnotNims:
|
when not defined(nimscript):
|
||||||
proc writeStackTrace*() {.tags: [], gcsafe, raises: [].}
|
proc writeStackTrace*() {.tags: [], gcsafe, raises: [].}
|
||||||
## Writes the current stack trace to ``stderr``. This is only works
|
## Writes the current stack trace to ``stderr``. This is only works
|
||||||
## for debug builds. Since it's usually used for debugging, this
|
## for debug builds. Since it's usually used for debugging, this
|
||||||
|
|
|
||||||
|
|
@ -105,6 +105,11 @@ proc rawWriteStackTrace(): string =
|
||||||
else:
|
else:
|
||||||
result = "No stack traceback available\n"
|
result = "No stack traceback available\n"
|
||||||
|
|
||||||
|
proc writeStackTrace() =
|
||||||
|
var trace = rawWriteStackTrace()
|
||||||
|
trace.setLen(trace.len - 1)
|
||||||
|
echo trace
|
||||||
|
|
||||||
proc getStackTrace*(): string = rawWriteStackTrace()
|
proc getStackTrace*(): string = rawWriteStackTrace()
|
||||||
proc getStackTrace*(e: ref Exception): string = e.trace
|
proc getStackTrace*(e: ref Exception): string = e.trace
|
||||||
|
|
||||||
|
|
|
||||||
12
tests/js/twritestacktrace.nim
Normal file
12
tests/js/twritestacktrace.nim
Normal file
|
|
@ -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()
|
||||||
Loading…
Add table
Add a link
Reference in a new issue