Skip to content

Commit c8053d4

Browse files
authored
fix: Fix creating error out of object (#784)
## Description Partially fixes problems of #783 with uninformative error ### Introduces a breaking change? - [ ] Yes - [x] No ### Type of change - [x] Bug fix (change which fixes an issue) - [ ] New feature (change which adds functionality) - [ ] Documentation update (improves or adds clarity to existing documentation) - [ ] Other (chores, tests, code style improvements etc.) ### Tested on - [x] iOS - [ ] Android ### Testing instructions Run code as in #783 described. Then apply fix and check if the error message is now created correctly. ### Screenshots <!-- Add screenshots here, if applicable --> ### Related issues <!-- Link related issues here using #issue-number --> ### Checklist - [x] I have performed a self-review of my code - [ ] I have commented my code, particularly in hard-to-understand areas - [ ] I have updated the documentation accordingly - [x] My changes generate no new warnings ### Additional notes <!-- Include any additional information, assumptions, or context that reviewers might need to understand this PR. -->
1 parent c6e2d72 commit c8053d4

1 file changed

Lines changed: 17 additions & 0 deletions

File tree

packages/react-native-executorch/src/errors/errorUtils.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,18 @@
11
import { RnExecutorchErrorCode } from './ErrorCodes';
22

3+
function isRnExecutorchError(
4+
e: unknown
5+
): e is { code: number; message: string } {
6+
return (
7+
typeof e === 'object' &&
8+
e !== null &&
9+
'code' in e &&
10+
'message' in e &&
11+
typeof (e as RnExecutorchError).code === 'number' &&
12+
typeof (e as RnExecutorchError).message === 'string'
13+
);
14+
}
15+
316
export class RnExecutorchError extends Error {
417
public code: RnExecutorchErrorCode;
518
public cause?: unknown;
@@ -13,6 +26,10 @@ export class RnExecutorchError extends Error {
1326
}
1427

1528
export function parseUnknownError(e: unknown): RnExecutorchError {
29+
if (isRnExecutorchError(e)) {
30+
return new RnExecutorchError(e.code, e.message);
31+
}
32+
1633
if (e instanceof RnExecutorchError) {
1734
return e;
1835
}

0 commit comments

Comments
 (0)