-
Notifications
You must be signed in to change notification settings - Fork 9
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
Async error from initializeInMain when the network is offline #19
Comments
Thanks for reporting this. I was able to reproduce it but I'm not yet sure how it's happening— we are not supposed to be allowing any uncaught promise rejections, since they are a major no-no that in some configurations can cause the process to exit. Also not yet sure if this is specific to the Electron SDK, or if it is an issue with our JS-based client-side SDKs in general. Continuing to investigate. |
We should have a patch out shortly, but just to clarify something: at some point in your startup code, you should wait for the client to finish initializing, because until that happens you will not get valid feature flag values from it. I believe you'll find that the following code does allow you to catch the error: ldclient = LDElectron.initializeInMain(ld_client_id, lduser, ldoptions);
try {
await ldclient.waitForInitialization();
// initialization succeeded
} catch (err) {
// initialization failed
} If you're not using ldclient = LDElectron.initializeInMain(ld_client_id, lduser, ldoptions);
ldclient.waitForInitialization().then(() => {
// initialization succeeded
}).catch(err => {
// initialization failed
}); Failure of initialization is reported in three ways: an |
update js-sdk-common and js-client-sdk to get event payload ID fix
Thanks for the feedback. I am already using the |
@clemkoa In Node, we support a few different mechanisms for this. The events you can listen for are described here, and the Promise-based methods are described here and here. Normally, listening for the "error" event (or "failed", which would mean it's an error that has stopped the client from starting up at all) would be a perfectly fine way to detect errors, if you prefer to use events. But what I was getting at in my previous comment is that there is currently a bug that causes errors to propagate as unhandled Promise rejections if you do not use client.waitForInitialization.then(() => {
// do whatever you want to do if startup has succeeded
}).catch(err => {
// do whatever you want to do if startup has failed
}); It's functionally equivalent to listening for an event, since you have to provide a callback either way. |
@clemkoa OK, we've released v1.5.1 with a fix for this, so you should be able to just keep doing what you were doing before rather than using the workaround I mentioned. Please let me know once you get a chance to try it out. |
I tested it and it works! Thanks for being so responsive! |
Describe the bug
When the computer is offline, calling initializeInMain fron the main process will throw an error. Trying to catch the error with something like this doesn't work:
The error seems to be from a promise inside the initializeInMain code.
To reproduce
Run this from a computer with no network connection:
Expected behavior
A sync error would be acceptable, I think it is weird to have an async error.
Logs
SDK version
1.4.3
Language version, developer tools
node v13.7.0
OS/platform
MacOS
Additional context
N/A
The text was updated successfully, but these errors were encountered: