Skip to content

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

Merged
merged 7 commits into from
Jun 27, 2024
Merged

Add MissingDependenciesError exception #13689

merged 7 commits into from
Jun 27, 2024

Conversation

whatyouhide
Copy link
Member

Message is up for debate 🙃

@josevalim
Copy link
Member

The issue comes down to the interpretation of dependency. A dependency does not mean a package. However, if we call it deps, then we are definitely tying it up to Mix interpretation of deps.

It also depends on which code we want people to write:

    If Application.spec(:foo_bar, :vsn) do

vs:

    if Code.ensure_loaded?(:foo_bar) do

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:

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"}

So I would go with MissingApplicationError after all, especially if we have to explain why this it not a Mix dependency.

@wojtekmach
Copy link
Member

big +1 for this. I like the MissingApplicationError name.

@wojtekmach
Copy link
Member

Just to add some more context, I could totally see it having been used in older versions of MyXQL/Postgrex that didn't have extra_applications: [:ssl], we were raising an exception with message along the lines of, well, add extra_applications: [:ssl]! That being said perhaps apps field should be renamed to deps?

@josevalim
Copy link
Member

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.

@wojtekmach
Copy link
Member

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 apps: [{:foobar, "~> 1.0"}] to me kind of mixes apps and deps. I think deps: [{:foobar, "~> 1.0"}] makes more sense to me in that regard.

@whatyouhide
Copy link
Member Author

The whole issue about deps is that their are a Mix concept

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 :deps in the current PR).

@josevalim
Copy link
Member

josevalim commented Jun 25, 2024

I disagree on this, "dependency" is a concept in software engineering not tied to Elixir or Mix

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.

@whatyouhide
Copy link
Member Author

Fair enough I guess 🙃 So we can go with MissingApplicationsError + :apps field then?

@josevalim
Copy link
Member

Given all trade offs, it seems to be the best one indeed.

@whatyouhide
Copy link
Member Author

@josevalim done!

@@ -2131,6 +2131,38 @@ defmodule UnicodeConversionError do
end
end

defmodule MissingApplicationsError do
Copy link
Member

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.

Copy link
Member Author

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?

Copy link
Member

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!

Copy link
Member Author

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)
"""
Copy link
Member

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.

Copy link
Member Author

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.

@whatyouhide whatyouhide requested a review from josevalim June 26, 2024 17:17

@typedoc since: "1.18.0"
@type t() :: %__MODULE__{
apps: [{Application.app(), Version.requirement()}, ...],
Copy link
Member

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?

Copy link
Member

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.

@whatyouhide whatyouhide merged commit f082b2d into main Jun 27, 2024
18 checks passed
@whatyouhide whatyouhide deleted the al/missing-dep-error branch June 27, 2024 07:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

4 participants