-
Notifications
You must be signed in to change notification settings - Fork 207
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
Unconstructable optional types provided to the container should not silently fail #269
Comments
There's a design decision to be made between the current behavior and this request:
So it's sorta a tradeoff between implicit and explicit behaviors, complicated because it applies transitively. Potentially worth pointing out:
I'm not particularly fond of "kitchen sink" modules... but the ease of implicit -> explicit does kinda make me prefer 1. It also makes intent of "optional, but not to me" clear in code. The difficulty of diagnosing failures might be fixable / improve-able with more logging, which I'm basically always in favor of. Since |
You are correct, I could have turned the soft error into a hard error but adding an I similarly had not considered the usecase of intentionally providing things that may not have satisfied dependencies knowing that the only thing that depends on them does so optionally. Had you asked me, before your response, to design this theoretical caching library I would have put just the core cache constructor in the I'm not sure I follow the argument of lib authors needing to provide no-op versions in your second scenario. Are you talking about a scenario where the library is providing a type the library consumer is going to depend on optionally? Or the other way around? Regardless, it does sound like this is squarely in "feature" not "bug" for better or worse. I will take away the |
It definitely does suck when it bites you. Implicit no-ops are frequently rage-inducing and take a long time to unravel, and I pretty much only know that strategy because I've fought with similar things a few times :)
It'd just be to achieve the same "provide everything, only satisfied stuff gets constructed" behavior, with the opposite implicit/explicit decision. You'd need to construct and return something for all the stuff you might provide, but it won't be usable without further checks. (though I suppose a nil pointer is pretty clear too, if you don't put it behind an interface) Not that I think that's a good alternative to
|
Take the following minimal example:
Running this will return the string
"a.c == nil is true"
. Despite the fact that a constructor wasProvide
d to the container for*C
, there is no feedback to the user thata.c == nil
because*C
's dependencies were not fulfilled. The only way to arrive at this conclusion without tracing back every optional dependency to all of their dependencies is to remove theoptional:"true"
tag temporarily and see what error dig returns when the container is resolved.Instead, I contend that when an optional dependency does have a constructor
Provide
d to the container, either (1) an error should always be returned if the optional dependency's dependencies cannot be met, or (2) a flag should able to be provided to the container (maybe some "strict" mode?) for cause optional dependency errors to be returned for easy debuggability.The text was updated successfully, but these errors were encountered: