NativeScript / NativeScript/napi-android
optional way of automatic native exception wrapping
Nobody has claimed this yet.
- Dominant language
- C++
- Stars
- 33
- Forks
- 3
- PR merge metrics
- No merged PRs in 30d
Description
Right now in the runtimes when a native exception is thrown which you catch with a try/catch it is the native exception object that you get.
So in my apps/N fork i use something like this:
export function wrapNativeException<T = any>(ex: NSError, wrapError: (...args) => T = (msg) => new Error(msg) as any) {
if (!ex) {
return;
}
if (typeof ex === 'string') {
return wrapError(ex);
}
if (!(ex instanceof Error)) {
const err = wrapError(ex.toString());
err['nativeException'] = ex;
//@ts-ignore
err['stackTrace'] = com.tns.NativeScriptException.getStackTraceAsString(ex);
return err;
}
return ex;
}
That method wraps the native exception in a JS error with stackTrace.
Would be pretty awesome to have that done automatically so that the error object you get in catch is an actual JS Error.
I think for now if we can do it it should be optional and disabled by default
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
No files, tests, or entry points are named. Start by locating native exception handling in the Android runtime and identifying how runtime options are configured. Done means an optional, disabled-by-default behavior produces a JavaScript Error with the native exception and stack trace when a native exception reaches catch.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- android, cpp, javascript, typescript
- Domain
- developer-experience, mobile-dev
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100