From 8fb04f45938296ba030fefaa164fe0e613a2c178 Mon Sep 17 00:00:00 2001 From: Balearica Date: Sat, 17 Sep 2022 16:33:20 -0700 Subject: [PATCH] Edited detect to return null when detection fails rather than throwing error per #526 --- src/index.d.ts | 10 +++++----- src/worker-script/index.js | 10 ++++++++-- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/index.d.ts b/src/index.d.ts index 7bebf77..f2cba0d 100644 --- a/src/index.d.ts +++ b/src/index.d.ts @@ -74,11 +74,11 @@ declare namespace Tesseract { data: DetectData } interface DetectData { - tesseract_script_id: number - script: string - script_confidence: number - orientation_degrees: number - orientation_confidence: number + tesseract_script_id: number | null + script: string | null + script_confidence: number | null + orientation_degrees: number | null + orientation_confidence: number | null } interface Rectangle { left: number diff --git a/src/worker-script/index.js b/src/worker-script/index.js index 60e9c64..ff0a732 100644 --- a/src/worker-script/index.js +++ b/src/worker-script/index.js @@ -356,9 +356,15 @@ const detect = async ({ payload: { image } }, res) => { const results = new TessModule.OSResults(); if (!api.DetectOS(results)) { - api.End(); TessModule._free(ptr); - res.reject('Failed to detect OS'); + + res.resolve({ + tesseract_script_id: null, + script: null, + script_confidence: null, + orientation_degrees: null, + orientation_confidence: null, + }); } else { const best = results.best_result; const oid = best.orientation_id;