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

nim js: appending a uninitialized string appends a null char '\0' #11788

Closed
timotheecour opened this issue Jul 19, 2019 · 1 comment
Closed

Comments

@timotheecour
Copy link
Member

timotheecour commented Jul 19, 2019

I was puzzled by the fact that my js stacktraces were missing depending on some obscure conditions.
It turns out it's caused by 2 bugs:

bug 1: nim js: appending a uninitialized string appends a null char '\0'

this is related to #11783 but seems different, as the bug in #11783 was only present when both appended and appendee were uninitialized, which isn't the case here.

Example

proc fun(): string =
  # result = "" # this removes the bug
  discard

var ret = "foo1"
ret.add fun()
# ret.add string.default # ditto with this
# ret.add "" # ditto with this
ret.add "foo2"
echo (ret, )
# using charCodeAt: reveals a 0
log(ret,)
doAssert false, ret

Current Output

nim js -r main.nim

("foo1\x00foo2",)
foo1foo2
/Users/timothee/git_clone/nim/timn/tests/nim/all/t0552.js:476
    throw new Error(cbuf_294801);
    ^

Error: Error: unhandled exception: /Users/timothee/git_clone/nim/timn/tests/nim/all/t0552.nim(17, 10) `false` foo1
# backtrace doesn't show!

Expected Output

("foo1\x00foo2",) should be ("foo1foo2",), and backtrace shouldn't truncate:

("foo1foo2",)
foo1foo2
/Users/timothee/git_clone/nim/timn/tests/nim/all/t0552.js:465
    throw new Error(cbuf_294801);
    ^

Error: Error: unhandled exception: /Users/timothee/git_clone/nim/timn/tests/nim/all/t0552.nim(17, 10) `false` foo1foo2 [AssertionError]
Traceback (most recent call last)
assertions.nim:27 assertions.failedAssertImpl
assertions.nim:20 assertions.raiseAssert
fatal.nim:39 sysFatal.sysFatal

    at unhandledException (/Users/timothee/git_clone/nim/timn/tests/nim/all/t0552.js:465:11)
    at raiseException (/Users/timothee/git_clone/nim/timn/tests/nim/all/t0552.js:266:3)
    at sys_fatal_288262 (/Users/timothee/git_clone/nim/timn/tests/nim/all/t0552.js:674:3)
...

bug 2:

the fact that the backtrace is truncated (missing all the stackframes) is actually a node bug, which i just filed here: nodejs/node#28761 ; it's just been confirmed
EDIT: that node bug itself just got fixed

Additional Information

  • Your Nim version (output of nim -v).
    latest devel f50e450
@timotheecour
Copy link
Member Author

timotheecour commented Apr 29, 2020

fixed by @hlaaftana 's awesome PR #14158; there's a new regression though (timotheecour#135), but it's unrelated:

Traceback (most recent call last)
assertions.nim:27 assertions.failedAssertImpl
assertions.nim:20 assertions.raiseAssert
fatal.nim:39 sysFatal.sysFatal

prints as:

Traceback (most recent call last)
module tscratch, line: 22
assertions.failedAssertImpl, line: 29
assertions.raiseAssert, line: 22
sysFatal.sysFatal, line: 49

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants