You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
I am trying to use this great package to build a VS code extension, however it's weird that I cannot catch the error outside even if i wrapped try catch block outside or add catch block after the createWorker call.
To Reproduce
Steps to reproduce the behavior:
can follow the link to create a hello-world example
modified the activate function code as follows
export async function activate(context: vscode.ExtensionContext) {
const disposable = vscode.commands.registerCommand(
'test.helloWorld',
async () => {
try {
console.log('before create worker')
const worker = await tesseract.createWorker();
console.log(worker); // this line cannot print in the debug console
vscode.window.showInformationMessage('Hello World from test!');
} catch (e) {
console.log('error', e);
}
}
);
context.subscriptions.push(disposable);
}
run debug this extension in the panel and type corresponding Hello World command in the test vscode window, then you can check the debug console you develop, it will print the logs
The logs only has 'before create worker', which means there is something wrong happens in the createWorker().
After the debugging, I found that it's because I didn't specify the workerPath which cause the spawnWorker() function failed. However, I cannot catch the bugs outside, could anyone helps to look at if I am doing a wrong catch way?
Expected behavior
Can catch the error outside.
The text was updated successfully, but these errors were encountered:
I was able to replicate what you describe, thanks for reporting this issue. I think this will require a patch to Tesseract.js to resolve. The core issue appears to be that the onerror function (line 42 in your screenshot) is being attached after the error occurs (line 40 in your screenshot).
This seems like something many other projects would encounter (and document a solution to) when working with workers, however upon a brief web search, I was unable to find any way to get the onerror function to trigger for an error during the creation of the worker. Perhaps some cleaner solution exists, but one idea is to send a "dummy" message to the worker immediately after creation, and throwing an error if no response is received after a set timeout.
This problem appears to be specific to Electron (which I believe VSCode uses), and does not occur in the browser. In addition to the fact that createWorker does not fail using default settings in the browser, if we run your code with an intentionally incorrect workerPath value, we can confirm that the catch block is entered.
Describe the bug
I am trying to use this great package to build a VS code extension, however it's weird that I cannot catch the error outside even if i wrapped try catch block outside or add catch block after the
createWorker
call.To Reproduce
Steps to reproduce the behavior:
activate
function code as followsdebug this extension
in the panel and type correspondingHello World
command in the test vscode window, then you can check the debug console you develop, it will print the logsThe logs only has 'before create worker', which means there is something wrong happens in the
createWorker()
.After the debugging, I found that it's because I didn't specify the
workerPath
which cause thespawnWorker()
function failed. However, I cannot catch the bugs outside, could anyone helps to look at if I am doing a wrong catch way?Expected behavior
Can catch the error outside.
The text was updated successfully, but these errors were encountered: