From d384d10e1b3b5079baadb29bdf367b9fda0ee9d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20S=C5=82uszniak?= Date: Wed, 4 Feb 2026 13:11:06 +0100 Subject: [PATCH 1/3] chore: Fix creating error out of object --- packages/react-native-executorch/src/errors/errorUtils.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/react-native-executorch/src/errors/errorUtils.ts b/packages/react-native-executorch/src/errors/errorUtils.ts index cc32f314b..6c2e67852 100644 --- a/packages/react-native-executorch/src/errors/errorUtils.ts +++ b/packages/react-native-executorch/src/errors/errorUtils.ts @@ -25,5 +25,8 @@ export function parseUnknownError(e: unknown): RnExecutorchError { return new RnExecutorchError(RnExecutorchErrorCode.Internal, e); } - return new RnExecutorchError(RnExecutorchErrorCode.Internal, String(e)); + const message = + typeof e === 'object' && e !== null ? JSON.stringify(e) : String(e); + + return new RnExecutorchError(RnExecutorchErrorCode.Internal, message); } From 0d7fe954da691b10f54dcec1298fd26fdcd0aedf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20S=C5=82uszniak?= Date: Wed, 4 Feb 2026 14:09:53 +0100 Subject: [PATCH 2/3] Fix handling error in more graceful way --- .../src/errors/errorUtils.ts | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/packages/react-native-executorch/src/errors/errorUtils.ts b/packages/react-native-executorch/src/errors/errorUtils.ts index 6c2e67852..8dc22e982 100644 --- a/packages/react-native-executorch/src/errors/errorUtils.ts +++ b/packages/react-native-executorch/src/errors/errorUtils.ts @@ -13,6 +13,18 @@ export class RnExecutorchError extends Error { } export function parseUnknownError(e: unknown): RnExecutorchError { + if ( + typeof e === 'object' && + e !== null && + 'code' in e && + 'message' in e && + typeof (e as any).code === 'number' && + typeof (e as any).message === 'string' + ) { + const raw = e as { code: number; message: string }; + return new RnExecutorchError(raw.code, raw.message); + } + if (e instanceof RnExecutorchError) { return e; } @@ -25,8 +37,5 @@ export function parseUnknownError(e: unknown): RnExecutorchError { return new RnExecutorchError(RnExecutorchErrorCode.Internal, e); } - const message = - typeof e === 'object' && e !== null ? JSON.stringify(e) : String(e); - - return new RnExecutorchError(RnExecutorchErrorCode.Internal, message); + return new RnExecutorchError(RnExecutorchErrorCode.Internal, String(e)); } From b752ab0fbcdb05f6eacc4882a79d184167576796 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20S=C5=82uszniak?= Date: Wed, 4 Feb 2026 14:44:24 +0100 Subject: [PATCH 3/3] fix: Make code more elegant --- .../src/errors/errorUtils.ts | 25 +++++++++++-------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/packages/react-native-executorch/src/errors/errorUtils.ts b/packages/react-native-executorch/src/errors/errorUtils.ts index 8dc22e982..79128cb85 100644 --- a/packages/react-native-executorch/src/errors/errorUtils.ts +++ b/packages/react-native-executorch/src/errors/errorUtils.ts @@ -1,5 +1,18 @@ import { RnExecutorchErrorCode } from './ErrorCodes'; +function isRnExecutorchError( + e: unknown +): e is { code: number; message: string } { + return ( + typeof e === 'object' && + e !== null && + 'code' in e && + 'message' in e && + typeof (e as RnExecutorchError).code === 'number' && + typeof (e as RnExecutorchError).message === 'string' + ); +} + export class RnExecutorchError extends Error { public code: RnExecutorchErrorCode; public cause?: unknown; @@ -13,16 +26,8 @@ export class RnExecutorchError extends Error { } export function parseUnknownError(e: unknown): RnExecutorchError { - if ( - typeof e === 'object' && - e !== null && - 'code' in e && - 'message' in e && - typeof (e as any).code === 'number' && - typeof (e as any).message === 'string' - ) { - const raw = e as { code: number; message: string }; - return new RnExecutorchError(raw.code, raw.message); + if (isRnExecutorchError(e)) { + return new RnExecutorchError(e.code, e.message); } if (e instanceof RnExecutorchError) {