-
-
Notifications
You must be signed in to change notification settings - Fork 153
Formatted lines with 80 characters, null crash fix, English fixes #144
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
Formatted lines with 80 characters, null crash fix, English fixes #144
Conversation
' type ${T.toString()} is not registered inside GetIt. ' | ||
'\n(Did you accidentally do GetIt sl=GetIt.instance(); instead of GetIt sl=GetIt.instance;' | ||
'\nDid you forget to register it?)', | ||
); | ||
|
||
return instanceFactory!; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This line caused a hard crash in a production app because assert()
did not run. In general, use of !
is discouraged and one should find an alternative to yield the eventual logic.
In this case, for example, one can use throwIf()
which is guaranteed to run in production.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I disagree, if you your crash wasn't caught during debug something is wrong how you test your code and normally you always have some gloabl execption handler that logs such cases.
Also you didn't change the assert. How did you fix the problem?
Anybody here? @escamoteur? |
Hi, sorry I forgot to merge you. Will do it today Am 07.01.2021 00:02 schrieb Noor Dawod <[email protected]>:
Anybody here? @escamoteur?
—You are receiving this because you were mentioned.Reply to this email directly, view it on GitHub, or unsubscribe.
|
Reminder @escamoteur |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi,
thanks for your PR.
My problem is, that it was intentional that the line length was set to 80, because pub's rating system punishes you if you use another length. Don't know if they have changed it. As this is a prerelease we probably can try.
Please see my other comments.
cheers
Thomas
@@ -0,0 +1,10 @@ | |||
root = true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fot which editor it this config file?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see you're working in VSCode. I work in IntelliJ IDEA. The beauty of .editorconfig
is that it's cross-IDE and most IDEs out there can understand it and follow its configuration.
' type ${T.toString()} is not registered inside GetIt. ' | ||
'\n(Did you accidentally do GetIt sl=GetIt.instance(); instead of GetIt sl=GetIt.instance;' | ||
'\nDid you forget to register it?)', | ||
); | ||
|
||
return instanceFactory!; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I disagree, if you your crash wasn't caught during debug something is wrong how you test your code and normally you always have some gloabl execption handler that logs such cases.
Also you didn't change the assert. How did you fix the problem?
I can reformat with 80 characters, no worries. Regarding the crash: If you notice I added a couple of new methods and then used them in /// Tests if an [instance] of an object or aType [T] or a name [instanceName]
/// is registered inside GetIt
@override
bool isRegistered<T extends Object>({
Object? instance,
String? instanceName,
}) {
if (instance != null) {
return _findFirstFactoryByInstanceOrNull(instance) != null;
} else {
return _findFirstFactoryByNameAndTypeOrNull<T>(instanceName) != null;
}
} Today, |
@escamoteur reformatted the code to be 80 characters using |
Hi, please never do a reformating and a shcnage in the same PR. I couldn't spot your changes because the diff is all red because of the reformatting. |
Forget it. This is the most inhospitable repo on the planet, I'm changing DI. |
Sorry if you call it inhospital to ask reasonable question. |
I explained twice already. Re-read. |
I just reread the whole converstion and you didn't. You proposed at the beginning we could use ´throwIf´but then you went for another solution without any explanation. |
3rd time is charm maybe... repeating: Regarding the crash: If you notice I added a couple of new methods and then used them in /// Tests if an [instance] of an object or aType [T] or a name [instanceName]
/// is registered inside GetIt
@override
bool isRegistered<T extends Object>({
Object? instance,
String? instanceName,
}) {
if (instance != null) {
return _findFirstFactoryByInstanceOrNull(instance) != null;
} else {
return _findFirstFactoryByNameAndTypeOrNull<T>(instanceName) != null;
}
} Today, I'll simplify more: Current code in PROD:
Proposed fix:
I hope this clears things up now? |
I totally got that. My question was why not just change the assert to a ´throwIf´ then isRegistered would work as expected? |
I believe it would work because Closing this pr. |
ps: there were some English grammatical fixes but you can do that at your leisure. |
Would love to only how to filter them out of the formatting? |
Glad this got merged! I think it was a good call. |
Did you run the tests after the changes? Because here they failed after the merge. You did forget to pass T from _findFactoryByTypeAndName to your _findFirstFactoryOrNull |
Thanks again for your effort. After I copied the latest version from your PR into a new branch locally I could easier follow what you had changed. |
Right, good! Will you fix the issue with passing T? |
Already done and new versions on pub |
Thanks @escamoteur, this has been a good experience :) |
I accept this as an apology ;-) |
Might as well :) |
In a production app I used get_it and I had a crash with the nullsafety branch. Turns out that
isRegistered()
calls_findFactoryByNameAndType()
which throws an exception because the returned value is null, but is silenced using the bang (!) character.So I fixed that and also reformatted the source code to 100 characters per line (it was not formatted it seemed). Also, many English grammatical and pronunciation errors were fixed.