Skip to content

Commit

Permalink
feat: put stacktraces in exceptions if possible (#291)
Browse files Browse the repository at this point in the history
This makes debugging exceptions and defects easier when using nimpy.
Maybe should also check for linetraces though?
  • Loading branch information
Okabintaro committed Sep 18, 2023
1 parent c21c081 commit 0a26251
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion nimpy.nim
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,12 @@ proc updateStackBottom() {.inline.} =
proc pythonException(e: ref Exception): PPyObject =
let err = pyLib.PyErr_NewException(cstring("nimpy" & "." & $(e.name)), pyLib.NimPyException, nil)
decRef err
pyLib.PyErr_SetString(err, cstring("Unexpected error encountered: " & e.msg))
let errMsg: string =
when compileOption("stackTrace"):
"Unexpected error encountered: " & e.msg & "\nstack trace: (most recent call last)\n" & e.getStackTrace()
else:
"Unexpected error encountered: " & e.msg
pyLib.PyErr_SetString(err, errmsg.cstring)

proc iterNext(i: PPyObject): PPyObject {.cdecl.} =
updateStackBottom()
Expand Down

0 comments on commit 0a26251

Please sign in to comment.