Skip to content

Commit f63b5d1

Browse files
committed
fix(models): throw RnExecutorchError on unsupported OCR language
The craft() OCR accessor was throwing a plain Error when called with an unpublished language; use RnExecutorchError with LanguageNotSupported so consumers can switch on code like every other error path.
1 parent 4d9ce61 commit f63b5d1

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

packages/react-native-executorch/src/constants/modelRegistry.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ import {
2525
KOKORO_GERMAN_FEMALE_ANNA,
2626
} from './tts/voices';
2727
import { TextToSpeechModelConfig } from '../types/tts';
28+
import { RnExecutorchError } from '../errors/errorUtils';
29+
import { RnExecutorchErrorCode } from '../errors/ErrorCodes';
2830

2931
/**
3032
* Backend options accepted by `models` accessors.
@@ -425,7 +427,8 @@ const OCR_BY_LANGUAGE: Partial<Record<SupportedLanguage, OcrConfig>> = (() => {
425427
function craft({ language }: { language: SupportedLanguage }): OcrConfig {
426428
const cfg = OCR_BY_LANGUAGE[language];
427429
if (!cfg) {
428-
throw new Error(
430+
throw new RnExecutorchError(
431+
RnExecutorchErrorCode.LanguageNotSupported,
429432
`OCR is not published for language '${language}'. ` +
430433
`Supported: ${Object.keys(OCR_BY_LANGUAGE).sort().join(', ')}`
431434
);

0 commit comments

Comments
 (0)