NativeScript / NativeScript/napi-android
optional way of automatic native exception wrapping
未关闭
还没有人认领这个 Issue。
- 主要语言
- C++
- 星标
- 33
- 派生
- 3
- PR 合并指标
- 30 天内没有已合并 PR
描述
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
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
未指定任何文件、测试或入口点。首先定位 Android runtime 中的原生异常处理,并确定如何配置 runtime 选项。当原生异常到达 catch 时,一个默认禁用的可选行为能够生成包含原生异常和堆栈跟踪的 JavaScript Error,即表示完成。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- android, cpp, javascript, typescript
- 领域
- developer-experience, mobile-dev
- Issue 类型
- 功能
- 难度
- 5/5
- 预计耗时
- 一周以上
- 活跃度
- 停滞
- 描述清晰度
- 需要澄清
- 新手友好度
- 25/100