Skip to content

Commit 3f0bf8a

Browse files
authored
fix: error messages formatting (#476) (#492)
## Description Fix error messages formatting from ``` [Error: UndefinedErrorModuleNotLoaded] ``` to: ``` [Error: MultilingualConfiguration] ``` ### 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 ### Checklist - [x] I have performed a self-review of my code - [x] I have commented my code, particularly in hard-to-understand areas - [ ] I have updated the documentation accordingly - [x] My changes generate no new warnings
1 parent b818f8a commit 3f0bf8a

1 file changed

Lines changed: 6 additions & 10 deletions

File tree

  • packages/react-native-executorch/src

packages/react-native-executorch/src/Error.ts

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export enum ETError {
77
LanguageNotSupported = 0x69,
88
InvalidModelSource = 0xff,
99

10-
//SpeechToText errors
10+
// SpeechToText errors
1111
MultilingualConfiguration = 0xa0,
1212
MissingDataChunk = 0xa1,
1313
StreamingNotStarted = 0xa2,
@@ -43,20 +43,16 @@ export enum ETError {
4343

4444
export const getError = (e: unknown | ETError | Error): string => {
4545
if (typeof e === 'number') {
46-
if (e in ETError) return ETError[e] as string;
47-
return ETError[ETError.UndefinedError] as string;
46+
return ETError[e] ?? ETError[ETError.UndefinedError];
4847
}
4948

5049
// try to extract number from message (can contain false positives)
5150
const error = e as Error;
5251
const errorCode = parseInt(error.message, 10);
53-
const message = Number.isNaN(errorCode)
54-
? error.message
55-
: ' ' + error.message.slice(`${errorCode}`.length).trimStart();
5652

57-
const ETErrorMessage = (
58-
errorCode in ETError ? ETError[errorCode] : ETError[ETError.UndefinedError]
59-
) as string;
53+
if (Number.isNaN(errorCode)) {
54+
return error.message;
55+
}
6056

61-
return ETErrorMessage + message;
57+
return ETError[errorCode] ?? ETError[ETError.UndefinedError];
6258
};

0 commit comments

Comments
 (0)