-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Add MissingDependenciesError exception #13689
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
The issue comes down to the interpretation of dependency. A dependency does not mean a package. However, if we call it It also depends on which code we want people to write:
vs:
At compile-time, it does not matter. At runtime, the first one is better if you assume the app may not be available. So, how do we want people to use it? I would say this:
and it should raise:
So I would go with |
big +1 for this. I like the |
Just to add some more context, I could totally see it having been used in older versions of MyXQL/Postgrex that didn't have |
We could list OTP applications and handle especially if desired. The whole issue about deps is that their are a Mix concept, it is not part of Elixir per se. |
Right, my point was not to necessarily (if that's what you're getting at) add first class support for missing OTP apps but exactly that |
I disagree on this, "dependency" is a concept in software engineering not tied to Elixir or Mix, so I think it's generic enough to justify its usage here. I agree though that the field in the exception probably sounds better if the name is the same as the exception (so it would be |
Yes but Elixir has existed for 10+ years and the meaning of the word deps to Elixir has always been clear. It is like saying "tasks" do not mean async/concurrent processing, but in Elixir they are pretty much synonyms. |
Fair enough I guess 🙃 So we can go with |
Given all trade offs, it seems to be the best one indeed. |
@josevalim done! |
@@ -2131,6 +2131,38 @@ defmodule UnicodeConversionError do | |||
end | |||
end | |||
|
|||
defmodule MissingApplicationsError do |
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.
Sorry, we have gone through some many bikesheds. I think last we talked it was meant to be singular? MissingApplicationError? I am fine either way, we should just double check.
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.
We agreed on plural IIRC, because we have a list of apps in the exception?
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 thought some found it weird because we don’t have many plurals in module names. Your call!
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.
Well it's still the singular Error
so let's go with MissingApplicationsError
😄
|
||
* :logger (~> 1.18) | ||
* :ex_unit (>= 0.0.0) | ||
""" |
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.
Here is my suggestion for the raising:
unless Application.spec(:foo_bar, :vsn) do
raise MissingApplicationError,
description: "application :foobar is required for feature xyz",
apps: [{:foobar, "~> 1.0"}]
end
and it should raise:
** (MissingApplicationError) application :foobar is required for feature xyz
To address this, include this application as your dependency:
{:foobar, "~> 1.0"}
I would keep them as tuples, because it is easier to copy and paste.
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 would keep them as tuples, because it is easier to copy and paste.
Good call.
Co-authored-by: José Valim <[email protected]>
|
||
@typedoc since: "1.18.0" | ||
@type t() :: %__MODULE__{ | ||
apps: [{Application.app(), Version.requirement()}, ...], |
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 mentioned earlier that a potential use case for this is raising on missing Elixir/OTP apps. If so, apps being non-empty makes it a bit awkward imo:
raise MissingApplicationsError,
description: "please add :ssl to :extra_applications",
apps: [{:ssl, ">= 0.0.0"}]
** (MissingApplicationsError) please add :ssl to :extra_applications
To address this, include these applications as your dependencies:
{:ssl, ">= 0.0.0"}
It's OK if this exception is not intended for that. Alternatively, allow :apps to be empty?
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.
We can detect if the application comes from OTP and change the message accordingly. So no concerns here.
Co-authored-by: José Valim <[email protected]>
Co-authored-by: Wojtek Mach <[email protected]>
Message is up for debate 🙃