Skip to content

[null safety] Bugfix in isRegistered() #147

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

Conversation

noordawod
Copy link
Contributor

This fixes a bug where production deployments will cause isRegistered<T>() to crash when T is not registered yet.

@@ -725,8 +726,6 @@ class _GetItImplementation implements GetIt {

for (final type in dependsOn) {
final dependentFactory = _findFactoryByNameAndType(null, type);
throwIf(dependentFactory == null,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, this is now interesting. Hadn't thought of this consequences because clearly the Exception thrown here conatins more information that the more generic one that gets thrown be _findFactoryByNameAndType.
So either we would have to wrap the _findFactory call in a try-catch or switch back to your solution returning null.
I fear I have to revisit where finding errors should be handled, Because even in debug the assert in _findFactory had robbed you off that information.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My way of writing code is not to meddle with try-catch too much and to prefer code, like I did before. What do you prefer?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason why I put the asserts inside the _findFactory was that I wanted to avaoid having to put an error check everywhere it was used.
I will take the last version of your previous PR and compare it to the current source. As it's again formatted with 80 characters It should be easier to read.
As I never used isRegistered in my own Apps it was important that you found the bug.

@noordawod noordawod closed this Jan 10, 2021
@noordawod noordawod deleted the bugfix/null-safety/is-registered branch January 10, 2021 15:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants