Closed jfilby closed 1 year ago
Or, catch
from Nim and throw
it in JS. Anything else can be done from your JS code.
Example, trying to parse some invalid JSON using std/json
. Exception message + stack trace:
myaddonWithErrors()
^
Error: input(1, 5) Error: { expected
/tests/myaddon.nim(30) wrapper$
/tests/myaddon.nim(13) testException
/.choosenim/toolchains/nim-1.6.14/lib/pure/json.nim(1035) parseJson
/.choosenim/toolchains/nim-1.6.14/lib/pure/json.nim(951) parseJson
/.choosenim/toolchains/nim-1.6.14/lib/pure/json.nim(916) parseJson
/.choosenim/toolchains/nim-1.6.14/lib/pure/parsejson.nim(515) raiseParseErr
at Object.<anonymous> (/tests/js/myaddon.js:4:5)
at Module._compile (node:internal/modules/cjs/loader:1256:14)
at Module._extensions..js (node:internal/modules/cjs/loader:1310:10)
at Module.load (node:internal/modules/cjs/loader:1119:32)
at Module._load (node:internal/modules/cjs/loader:960:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
at node:internal/main/run_main_module:23:47 {
code: 'NimRuntime'
}
Starting with v0.1.7
it will be available in {.export_napi.}
pragma
That's really great! Thanks.
I noticed that when an exception is raised from the Nim code in the addon, the exception not displayed in the console and any future Nim calls don't work. The node process has to be restarted.
It might be useful for Denim to catch all exceptions and log them to the console in a harmless way.