{"record":{"id":"f530444680836f19","repo":"naptha/tesseract.js","slug":"data","errorCode":null,"errorMessage":"${data}","messagePattern":"\\$\\{data\\}","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"critical","filePath":"src/createWorker.js","lineNumber":217,"sourceCode":"    return Promise.resolve();\n  };\n\n  onMessage(worker, ({\n    workerId, jobId, status, action, data,\n  }) => {\n    const promiseId = `${action}-${jobId}`;\n    if (status === 'resolve') {\n      log(`[${workerId}]: Complete ${jobId}`);\n      promises[promiseId].resolve({ jobId, data });\n      delete promises[promiseId];\n    } else if (status === 'reject') {\n      promises[promiseId].reject(data);\n      delete promises[promiseId];\n      if (action === 'load') workerResReject(data);\n      if (errorHandler) {\n        errorHandler(data);\n      } else {\n        throw Error(data);\n      }\n    } else if (status === 'progress') {\n      logger({ ...data, userJobId: jobId });\n    }\n  });\n\n  const resolveObj = {\n    id,\n    worker,\n    load,\n    writeText,\n    readText,\n    removeFile,\n    FS,\n    reinitialize,\n    setParameters,\n    recognize,\n    detect,","sourceCodeStart":199,"sourceCodeEnd":235,"githubUrl":"https://github.com/naptha/tesseract.js/blob/a1ca80d9e31c34512d0ded75ff8821ddcf3f2f91/src/createWorker.js#L199-L235","documentation":"When the worker thread rejects a job (status === 'reject'), onMessage rejects the corresponding promise and then either invokes the user-supplied errorHandler or, if none was provided, runs throw Error(data) inside the message-event listener. Because that listener is not an awaited async function, the throw surfaces as an uncaught exception rather than a normal rejection, and the thrown message is just the stringified worker-side error data.","triggerScenarios":"Any worker-side job rejection (image decode failure, recognize crash, FS error) when createWorker was called without an errorHandler option. The same rejection is delivered twice: once to the awaited promise, once as the uncaught throw.","commonSituations":"Default config in Node.js where no errorHandler is set; image/load failures during processing crashing the process; confusing double-reporting of the same error.","solutions":["Pass errorHandler: (err) => { /* log/handle */ } in the options to createWorker — this replaces the throw.","Ensure every awaited worker job has a .catch() so the promise rejection path is handled.","As a last line of defense, register a process-level uncaughtException listener in Node.js."],"exampleFix":"// before\nconst worker = await createWorker('eng'); // no errorHandler\nawait worker.recognize(badImg); // worker rejects -> uncaught throw\n\n// after\nconst worker = await createWorker('eng', {\n  errorHandler: (err) => console.error('worker error:', err),\n});\ntry { await worker.recognize(badImg); } catch (e) { /* handled */ }","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"// Always pass an errorHandler so the internal `throw Error(data)` branch is never reached.\nconst worker = await createWorker('eng', OEM.LSTM_ONLY, {\n  errorHandler: (err) => {\n    // log/transport; do NOT rethrow inside the message listener\n    logger.error('tesseract worker error:', err);\n  },\n});\n\n// AND always await jobs inside try/catch:\ntry {\n  const { data } = await worker.recognize(image);\n} catch (jobErr) {\n  // the promise-rejection path; safe to handle/rethrow here\n  logger.error('recognize failed:', jobErr);\n}","preventionTips":["Always pass an errorHandler in createWorker options; it replaces the uncaught throw.","Never assume a worker job will resolve — wrap every await in try/catch.","Register a process-level uncaughtException / window.onerror handler as a safety net.","Log both the awaited-promise rejection and the errorHandler argument to deduplicate reports."],"tags":["error-handling","uncaught-exception","worker","node"],"backgroundTag":null,"analyzedSha":"a1ca80d9e31c34512d0ded75ff8821ddcf3f2f91","analyzedAt":"2026-08-13T04:28:13.744Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}