Print a nicer error message when a Python function is not found

This commit is contained in:
Pavel Panchekha 2021-11-17 11:10:41 -07:00
parent 15f93b24f3
commit 8552a310de
2 changed files with 13 additions and 0 deletions

View File

@ -69,6 +69,10 @@ class JSInterpreter(object):
"""
self._funcs[name] = func
def _check_exported_function_exists(self, func):
func = func.decode('utf-8')
return func in self._funcs
def _call_python(self, func, json_args):
# Arguments came in reverse order from JS
func = func.decode('utf-8')

View File

@ -73,6 +73,15 @@ int call_py_function(duk_context *ctx) {
duk_pop(ctx);
duk_pop(ctx);
ret = PyObject_CallMethod(interpreter, "_check_exported_function_exists",
CONDITIONAL_PY3("y", "s"), pyfuncname);
if (ret == Py_False) {
duk_push_error_object(ctx, DUK_ERR_REFERENCE_ERROR,
"No Python Function named %s", pyfuncname);
duk_throw(ctx);
}
ret = PyObject_CallMethod(interpreter, "_call_python", CONDITIONAL_PY3("yy", "ss"),
pyfuncname, args);