duktape
duktape copied to clipboard
Is it possible to add additional information to the javascript errors when using duk_push_c_function?
I work with some code that connects duktape
to a Haskell system, part of this system involves converting JS values to Haskell types, in order to call Haskell functions, running them using Haskell's FFI to C and duk_push_c_function
.
Currently, the function arguments are decoded one by one, and if they fail to convert (and therefore will not be usable in Haskell) then the function will return the relevant number (in this case -6
) to trigger a TypeError
.
However, the TypeError
that is raised contains no information specifically about what failed to decode and why, so I would like to make modifications to it to include this (or just add a custom error message generally).
AFAICT this is not possible with duk_push_c_function
? As you can only return some number that maps to an error. I tried using duk_throw
and duk_push_error_object
to trigger a custom error, but this does not work, as it seems like the error needs to be triggered in the C
function that is passed in to duk_push_c_function
, which is where the Haskell code is actually run, and thus the code that detects that there is an error.
Is there some way in duktape to trigger custom errors from C
that actually propogate up to JS
as javascript errors? I was thinking that would be what I could do with duk_throw
, but it doesn't seem to do what I want it to do....