Skip to content

Commit

Permalink
Handle non-Error objects thrown in JS (#154)
Browse files Browse the repository at this point in the history
.stack may not exist so just stringify the whole error object
  • Loading branch information
extremeheat authored Jan 26, 2025
1 parent bd17b0d commit 5b3aecd
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
6 changes: 3 additions & 3 deletions src/javascript/js/bridge.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ class Bridge {
try {
this.m[ffid][attr] = val
} catch (e) {
return this.ipc.send({ r, key: 'error', error: e.stack })
return this.ipc.send({ r, key: 'error', error: e.stack || JSON.stringify(e) })
}
this.ipc.send({ r, key: '', val: true })
}
Expand All @@ -138,7 +138,7 @@ class Bridge {
var v = await this.m[ffid](...args) // eslint-disable-line
}
} catch (e) {
return this.ipc.send({ r, key: 'error', error: e.stack })
return this.ipc.send({ r, key: 'error', error: e.stack || JSON.stringify(e) })
}
const type = getType(v)
// console.log('GetType', type, v)
Expand Down Expand Up @@ -230,7 +230,7 @@ class Bridge {
}
await this[action](r, ffid, key, args)
} catch (e) {
return this.ipc.send({ r, key: 'error', error: e.stack })
return this.ipc.send({ r, key: 'error', error: e.stack || JSON.stringify(e) })
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/pythonia/jsi.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ class JSBridge {
try {
this.m[ffid][attr] = val
} catch (e) {
return this.ipc.send({ r, key: 'error', error: e.stack })
return this.ipc.send({ r, key: 'error', error: e.stack || JSON.stringify(e) })
}
this.ipc.send({ r, key: '', val: true })
}
Expand All @@ -113,7 +113,7 @@ class JSBridge {
var v = await this.m[ffid](...args) // eslint-disable-line
}
} catch (e) {
return this.ipc.send({ r, key: 'error', error: e.stack })
return this.ipc.send({ r, key: 'error', error: e.stack || JSON.stringify(e) })
}
const type = getType(v)
// console.log('GetType', type, v)
Expand Down Expand Up @@ -191,7 +191,7 @@ class JSBridge {
}
await this[action](r, ffid, key, args)
} catch (e) {
return this.ipc.send({ r, key: 'error', error: e.stack })
return this.ipc.send({ r, key: 'error', error: e.stack || JSON.stringify(e) })
}
}
}
Expand Down
4 changes: 4 additions & 0 deletions test/javascript/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ class DemoClass extends EventEmitter {
throw Error('This should fail')
}

error2 () {
throw {'non error': 'object'}
}

ok () {
function someMethod (a, b, c) {
return a + b + c
Expand Down

0 comments on commit 5b3aecd

Please sign in to comment.