Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature Request]: Exit App instance when main package throws error on load #40606

Open
3 tasks done
regnete opened this issue Nov 23, 2023 · 1 comment
Open
3 tasks done

Comments

@regnete
Copy link

regnete commented Nov 23, 2023

Preflight Checklist

Electron Version

27.0.2

What operating system are you using?

Windows

Operating System Version

Windows 10 Enterprise 22H2 19045.3693

What arch are you using?

x64

Last Known Working Electron version

n/a

Expected Behavior

If an error occurs while loading the main package an error message should be displayed and the app must exit with an error code.

Actual Behavior

If an error occurs while loading the main package an error message is displayed but the app contunues to run. In windows taskmanager several task 'name_of_the_app.exe' keep runing, even if the error panel is closed by hitting 'OK'.

Testcase Gist URL

No response

Additional Information

I guess the issue could be resolved by modifying code in

console.error('App threw an error during load');

Current code:

    console.error('App threw an error during load');
    console.error((e as Error).stack || e);
    throw e;

Fixed code:

    showErrorMessage(`App threw an error during load of ${packagePath}\n\n${(e as Error).stack || (e as Error).message || e}`);
@regnete
Copy link
Author

regnete commented Nov 27, 2023

Workarround until this is fixed: Encapsulate the whole main script in a try/catch block.

try
{
  
   ... main script code goes here ...

} catch (error)
{
    try
    {
        // avoid https://github.com/electron/electron/issues/40606
        console.error("cannot init main script", error);
        dialog.showErrorBox("Cannot start Electron App", error.stack || error);
    } finally
    {
        app.exit(1);
    }
}

regnete added a commit to sitewaerts/cordova-electron that referenced this issue Dec 1, 2023
@jkleinsc jkleinsc changed the title [Bug]: App instance not exiting when main package throws error on load [Feature Request]: Exit App instance when main package throws error on load Jan 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
No open projects
Status: No status
Status: 👍 Does Not Block Stable
Development

Successfully merging a pull request may close this issue.

3 participants