Compare commits

..

1 Commits
1.0.4 ... 1.0.5

Author SHA1 Message Date
4ac3036000 Proper error handling for OCR
All checks were successful
Publish Library / Build NPM Project (push) Successful in 43s
Publish Library / Tag Version (push) Successful in 11s
2026-06-09 09:41:09 -04:00
2 changed files with 8 additions and 4 deletions

View File

@@ -1,6 +1,6 @@
{
"name": "@ztimson/ai-utils",
"version": "1.0.4",
"version": "1.0.5",
"description": "AI Utility library",
"author": "Zak Timson",
"license": "MIT",

View File

@@ -14,9 +14,13 @@ export class Vision {
let worker: any;
const p = (async () => {
worker = await createWorker(this.ai.options.ocr || 'eng', 2, {cachePath: this.ai.options.path});
const {data} = await worker.recognize(path);
await worker.terminate();
return data.text.trim() || null;
worker.setParameters({}).catch(() => {}); // force error handler attachment
return await new Promise<string | null>((res, rej) => {
worker.on?.('error', rej); // catch worker-level throws
worker.recognize(path)
.then(({data}: any) => res(data.text.trim() || null))
.catch(rej);
});
})().finally(() => worker?.terminate());
return Object.assign(p, {abort: () => worker?.terminate()});
}