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

--gc:arc not self-consistent, not consistent with default gc regarding catching AssertionError #13585

Closed
timotheecour opened this issue Mar 4, 2020 · 3 comments

Comments

@timotheecour
Copy link
Member

--gc:arc not self-consistent, not consistent with default gc regarding catching AssertionError

  • consistency is important otherwise migrating code from non-gc:arc to gc:arc will be a pain.
  • This is especially true for any code involving testing, where it's common to catch AssertError, eg doAssertRaises, which is important to support to check that asserts in place work as intended.
  • there are other use cases beyond testing, eg for writing repl's and other tool where user input may raise non-catchable exceptions
  • ditto, when writing production servers that just shouldn't crash and would be caught at some root-level to perform important cleanups instead of exiting

Example

try:
  doAssert false # BUG
  # assert false # BUG
  # raiseAssert("foo") # BUG
  # raise newException(Exception, "foo") # works
  # raise newException(AssertionError, "foo") # works
  # raise newException(CatchableError, "foo") # works
except:
  echo "caught"
echo "after main"

Current Output

("goto", true)
Traceback (most recent call last)
/Users/timothee/git_clone/nim/timn/tests/nim/all/t10302.nim(8) t10302
/Users/timothee/git_clone/nim/Nim_devel/lib/system/assertions.nim(27) failedAssertImpl
/Users/timothee/git_clone/nim/Nim_devel/lib/system/assertions.nim(20) raiseAssert
/Users/timothee/git_clone/nim/Nim_devel/lib/system/fatal.nim(45) sysFatal
/Users/timothee/git_clone/nim/Nim_devel/lib/system/fatal.nim(33) sysFatal
Error: unhandled exception: /Users/timothee/git_clone/nim/timn/tests/nim/all/t10302.nim(8, 12) `false`  [AssertionError]

Expected Output

  • should be same as without --gc:arc and other gc's
  • should be same as with raise newException(AssertionError, "foo") etc
    all of which give:
caught
after main

Additional Information

@Araq
Copy link
Member

Araq commented Mar 4, 2020

This is the documented behaviour of --goto:exceptions and hence not a bug. I know it's disliked by many but that doesn't make it a bug.

@timotheecour
Copy link
Member Author

timotheecour commented Mar 6, 2020

This is the documented behaviour of --goto:exceptions

do you have a link? I'm not seeing any mention of assert here https://nim-lang.org/araq/gotobased_exceptions.html nor any mention of goto under https://nim-lang.github.io/Nim/manual.html#exception-handling

EDIT: I do see Caveats section in https://nim-lang.org/araq/gotobased_exceptions.html saying:

In the "goto based exceptions" mode checked runtime errors like "Index out of bounds" or integer overflows are not catchable and terminate the process. This is in compliance with the Nim spec, quoting the manual: Whether a checked runtime error results in an exception or in a fatal error is implementation specific.

https://nim-lang.github.io/Nim/manual.html#exception-handling should probably have some explicit mention of --exceptions:goto's behavior, instead of merely saying implementation specific under https://nim-lang.org/docs/manual.html#definitions

@timotheecour
Copy link
Member Author

fixed by #13626

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