Skip to content

Commit d6366de

Browse files
committed
fix: narrow unknown catch vars to Error in models.ts (#553)
After merging main (which includes PR #555's TS migration of models.ts), three catch clauses pass `unknown` to EngineError's `cause: Error` field. Use instanceof checks to satisfy strict typing.
1 parent 4425dbd commit d6366de

1 file changed

Lines changed: 5 additions & 4 deletions

File tree

src/domain/search/models.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ export async function loadTransformers(): Promise<unknown> {
143143
} catch (loadErr) {
144144
throw new EngineError(
145145
`${pkg} was installed but failed to load. Please check your environment.`,
146-
{ cause: loadErr },
146+
{ cause: loadErr instanceof Error ? loadErr : undefined },
147147
);
148148
}
149149
}
@@ -181,21 +181,22 @@ async function loadModel(modelKey?: string): Promise<{ extractor: unknown; confi
181181
await // biome-ignore lint/complexity/noBannedTypes: dynamically loaded transformers pipeline is untyped
182182
(pipeline as Function)('feature-extraction', config.name, pipelineOpts);
183183
} catch (err: unknown) {
184-
const msg = (err as Error).message || String(err);
184+
const cause = err instanceof Error ? err : undefined;
185+
const msg = cause?.message || String(err);
185186
if (msg.includes('Unauthorized') || msg.includes('401') || msg.includes('gated')) {
186187
throw new EngineError(
187188
`Model "${config.name}" requires authentication.\n` +
188189
`This model is gated on HuggingFace and needs an access token.\n\n` +
189190
`Options:\n` +
190191
` 1. Set HF_TOKEN env var: export HF_TOKEN=hf_...\n` +
191192
` 2. Use a public model instead: codegraph embed --model minilm`,
192-
{ cause: err },
193+
{ cause },
193194
);
194195
}
195196
throw new EngineError(
196197
`Failed to load model "${config.name}": ${msg}\n` +
197198
`Try a different model: codegraph embed --model minilm`,
198-
{ cause: err },
199+
{ cause },
199200
);
200201
}
201202
activeModel = config.name;

0 commit comments

Comments
 (0)