Skip to content

Commit 0822d49

Browse files
committed
fix(models): replace remaining plain Error throws with RnExecutorchError
The three sanity checks in firstBackend/resolveCell/resolveVariant were the last plain Error throws in modelRegistry. The first two are truly-internal invariants -> Internal; the backend-missing one is reachable from untyped callers -> InvalidConfig.
1 parent f63b5d1 commit 0822d49

1 file changed

Lines changed: 12 additions & 3 deletions

File tree

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

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,10 @@ function firstBackend(variants: AnyVariantMap): Backend {
8484
for (const b of BACKEND_ORDER) {
8585
if (variants[b]) return b;
8686
}
87-
throw new Error('Model variant map is empty.');
87+
throw new RnExecutorchError(
88+
RnExecutorchErrorCode.Internal,
89+
'Model variant map is empty.'
90+
);
8891
}
8992

9093
function resolveBackend(
@@ -116,7 +119,10 @@ function resolveCell(cell: BackendCell, quant: boolean): { modelName: string } {
116119
const fallback = quant ? cell.base : cell.quant;
117120
const result = primary ?? fallback;
118121
if (!result) {
119-
throw new Error('Model variant cell has no config.');
122+
throw new RnExecutorchError(
123+
RnExecutorchErrorCode.Internal,
124+
'Model variant cell has no config.'
125+
);
120126
}
121127
return result;
122128
}
@@ -129,7 +135,10 @@ function resolveVariant(
129135
const backend = resolveBackend(variants, platformDefaults, opts.backend);
130136
const cell = variants[backend];
131137
if (!cell) {
132-
throw new Error(`Backend '${backend}' is not available for this model.`);
138+
throw new RnExecutorchError(
139+
RnExecutorchErrorCode.InvalidConfig,
140+
`Backend '${backend}' is not available for this model.`
141+
);
133142
}
134143
return resolveCell(cell, opts.quant !== false);
135144
}

0 commit comments

Comments
 (0)