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

ansi_c: support rawWrite(cstderr|cstdout, s) in js, nodejs, vm #16125

Closed
wants to merge 6 commits into from

Conversation

timotheecour
Copy link
Member

@timotheecour timotheecour commented Nov 25, 2020

followup on #16016.

with this PR:

  • rawWrite(cstderr|cstdout, s) now works in js, nodejs, vm (and vm+js, vm+nodejs)
    this is useful in itself (in particular writing without newline for vm, unlike echo, or writing to stderr in vm/nodejs/js), and also avoids having to special case a lot of existing code using rawWrite for those backends.

  • writeStackTrace writes to stderr for js,nodejs, consistently with docs for writeStackTrace and with c backend

  • --panics:on now works better with js/nodejs (previously, would give stderr not defined)

example

proc fn() =
  writeStackTrace()
fn()

from system/ansi_c import rawWrite, cstderr, cstdout
rawWrite(cstderr, "ok1")
rawWrite(cstderr, "ok2\n")
rawWrite(cstdout, "ok3")
rawWrite(cstdout, "ok4\n")

doAssertRaises(AssertionDefect):
  doAssert false, "foo"

nim r --panics main:

Traceback (most recent call last)
/Users/timothee/git_clone/nim/timn/tests/nim/all/t11366.nim(7) t11366
/Users/timothee/git_clone/nim/timn/tests/nim/all/t11366.nim(6) fn
ok1ok2
ok3ok4
Traceback (most recent call last)
/Users/timothee/git_clone/nim/timn/tests/nim/all/t11366.nim(15) t11366
/Users/timothee/git_clone/nim/Nim_prs/lib/system/assertions.nim(30) failedAssertImpl
/Users/timothee/git_clone/nim/Nim_prs/lib/system/assertions.nim(23) raiseAssert
/Users/timothee/git_clone/nim/Nim_prs/lib/system/fatal.nim(45) sysFatal
/Users/timothee/git_clone/nim/Nim_prs/lib/system/fatal.nim(33) sysFatal
Error: unhandled exception: /Users/timothee/git_clone/nim/timn/tests/nim/all/t11366.nim(15, 43) `false` foo [AssertionDefect]

nim r -b:js --panics -d:nodejs main
almost same:

Traceback (most recent call last)
/Users/timothee/git_clone/nim/timn/tests/nim/all/t11366.nim(7) at module t11366
/Users/timothee/git_clone/nim/timn/tests/nim/all/t11366.nim(6) at t11366.fn
ok1ok2
ok3ok4
Traceback (most recent call last)
/Users/timothee/git_clone/nim/timn/tests/nim/all/t11366.nim(15) at module t11366
/Users/timothee/git_clone/nim/Nim_prs/lib/system/assertions.nim(30) at assertions.failedAssertImpl
/Users/timothee/git_clone/nim/Nim_prs/lib/system/assertions.nim(23) at assertions.raiseAssert
/Users/timothee/git_clone/nim/Nim_prs/lib/system/fatal.nim(45) at sysFatal.sysFatal
/Users/timothee/git_clone/nim/Nim_prs/lib/system/fatal.nim(33) at sysFatal.sysFatal

nim r -b:js --panics main

in this case it now correctly shows the AssertionDefect error + msg, but later fails for a different reason, because exit isn't defined; this can be fixed and is the same issue as #16074
Another caveat is rawWrite behaves more like some hypothetical rawWriteln

Traceback (most recent call last)
/Users/timothee/git_clone/nim/timn/tests/nim/all/t11366.nim(7) at module t11366
/Users/timothee/git_clone/nim/timn/tests/nim/all/t11366.nim(6) at t11366.fn

ok1
ok2

ok3
ok4

Traceback (most recent call last)
/Users/timothee/git_clone/nim/timn/tests/nim/all/t11366.nim(15) at module t11366
/Users/timothee/git_clone/nim/Nim_prs/lib/system/assertions.nim(30) at assertions.failedAssertImpl
/Users/timothee/git_clone/nim/Nim_prs/lib/system/assertions.nim(23) at assertions.raiseAssert
/Users/timothee/git_clone/nim/Nim_prs/lib/system/fatal.nim(45) at sysFatal.sysFatal
/Users/timothee/git_clone/nim/Nim_prs/lib/system/fatal.nim(33) at sysFatal.sysFatal

Error: unhandled exception: /Users/timothee/git_clone/nim/timn/tests/nim/all/t11366.nim(15, 43) `false` foo [AssertionDefect]

Traceback (most recent call last)
/Users/timothee/git_clone/nim/timn/tests/nim/all/t11366.nim(109) at module t11366
/Users/timothee/git_clone/nim/Nim_prs/lib/system/assertions.nim(23) at assertions.raiseAssert
/Users/timothee/git_clone/nim/Nim_prs/lib/system/fatal.nim(45) at sysFatal.sysFatal
/Users/timothee/git_clone/nim/Nim_prs/lib/system/fatal.nim(33) at sysFatal.sysFatal

Error: unhandled exception: expected raising 'AssertionDefect', instead raised foreign exception by:
doAssert false, "foo" [AssertionDefect]

/Users/timothee/git_clone/nim/timn/build/nimcache/t11366.js:506
    exit(1);
    ^

ReferenceError: exit is not defined
    at sysFatal_218103880 (/Users/timothee/git_clone/nim/timn/build/nimcache/t11366.js:506:5)

@stale
Copy link

stale bot commented Nov 25, 2021

This pull request has been automatically marked as stale because it has not had recent activity. If you think it is still a valid PR, please rebase it on the latest devel; otherwise it will be closed. Thank you for your contributions.

@stale stale bot added the stale Staled PR/issues; remove the label after fixing them label Nov 25, 2021
@stale stale bot closed this Dec 25, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stale Staled PR/issues; remove the label after fixing them
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant