hileez / node-pyrunner

Nodejs call python native addon.
MIT License
36 stars 2 forks source link

How to handle error in python or js #2

Closed LogikMeister closed 1 year ago

LogikMeister commented 1 year ago

python

...
def hello()
rasie Exception('error')
return 'hello from python'

js

appModule.call('hello', [],
(data) => {
consolo.log(data)
},
(err) => {
console.log(err)
}
)
  • Error node process exit with code 1

python

import nodepyrunner
...
try:
nodepyrunner.callJs(target='hello', args=[])
except:
print('some err')

js

global.hello = () => {
throw Error()
}
  • Error

FATAL ERROR: Error::New napi_get_last_error_info 1: 00007FF7E15FB34F v8::internal::CodeObjectRegistry::~CodeObjectRegistry+123599 2: 00007FF7E1588CB6 v8::internal::MicrotaskQueue::GetMicrotasksScopeDepth+65206 3: 00007FF7E1589D8D node::OnFatalError+301 4: 00007FF7E1589369 v8::internal::MicrotaskQueue::GetMicrotasksScopeDepth+66921 5: 00007FF7E15B73FC napi_fatal_error+156 ...

hileez commented 1 year ago

Node process ended because of python and javascript throw error. Python和JavaScript抛出异常都会导致node进程结束。