(#9717) Improve messaging around not finding requested provider
This commit adds a bit more helpful messaging for the user when asking for a provider that might not exist or does not follow the correct casing. If it can find a match on a provider it knows about, it will suggest it.
This commit is contained in:
parent
2b13a6a608
commit
fd3d78746c
|
@ -580,6 +580,10 @@ module Vagrant
|
||||||
error_key(:provider_not_found)
|
error_key(:provider_not_found)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
class ProviderNotFoundSuggestion < VagrantError
|
||||||
|
error_key(:provider_not_found_suggestion)
|
||||||
|
end
|
||||||
|
|
||||||
class ProviderNotUsable < VagrantError
|
class ProviderNotUsable < VagrantError
|
||||||
error_key(:provider_not_usable)
|
error_key(:provider_not_usable)
|
||||||
end
|
end
|
||||||
|
|
|
@ -125,8 +125,21 @@ module Vagrant
|
||||||
if provider != nil
|
if provider != nil
|
||||||
provider_plugin = Vagrant.plugin("2").manager.providers[provider]
|
provider_plugin = Vagrant.plugin("2").manager.providers[provider]
|
||||||
if !provider_plugin
|
if !provider_plugin
|
||||||
|
providers = Vagrant.plugin("2").manager.providers.to_hash.keys
|
||||||
|
if providers
|
||||||
|
providers_str = providers.join(', ')
|
||||||
|
else
|
||||||
|
providers_str = "N/A"
|
||||||
|
end
|
||||||
|
|
||||||
|
if providers.include? provider.downcase
|
||||||
|
raise Errors::ProviderNotFoundSuggestion,
|
||||||
|
machine: name, provider: provider,
|
||||||
|
suggestion: provider.downcase, providers: providers_str
|
||||||
|
end
|
||||||
|
|
||||||
raise Errors::ProviderNotFound,
|
raise Errors::ProviderNotFound,
|
||||||
machine: name, provider: provider
|
machine: name, provider: provider, providers: providers_str
|
||||||
end
|
end
|
||||||
|
|
||||||
provider_cls = provider_plugin[0]
|
provider_cls = provider_plugin[0]
|
||||||
|
|
|
@ -1172,6 +1172,15 @@ en:
|
||||||
provider_not_found: |-
|
provider_not_found: |-
|
||||||
The provider '%{provider}' could not be found, but was requested to
|
The provider '%{provider}' could not be found, but was requested to
|
||||||
back the machine '%{machine}'. Please use a provider that exists.
|
back the machine '%{machine}'. Please use a provider that exists.
|
||||||
|
|
||||||
|
Vagrant knows about the following providers: %{providers}
|
||||||
|
provider_not_found_suggestion: |-
|
||||||
|
The provider '%{provider}' could not be found, but was requested to
|
||||||
|
back the machine '%{machine}'. Please use a provider that exists.
|
||||||
|
|
||||||
|
Did you mean '%{suggestion}'?
|
||||||
|
|
||||||
|
Vagrant knows about the following providers: %{providers}
|
||||||
provider_not_usable: |-
|
provider_not_usable: |-
|
||||||
The provider '%{provider}' that was requested to back the machine
|
The provider '%{provider}' that was requested to back the machine
|
||||||
'%{machine}' is reporting that it isn't usable on this system. The
|
'%{machine}' is reporting that it isn't usable on this system. The
|
||||||
|
|
|
@ -329,6 +329,13 @@ describe Vagrant::Vagrantfile do
|
||||||
to raise_error(Vagrant::Errors::ProviderNotFound)
|
to raise_error(Vagrant::Errors::ProviderNotFound)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "raises an error if the provider is not found but gives suggestion" do
|
||||||
|
register_provider("foo")
|
||||||
|
|
||||||
|
expect { subject.machine_config(:default, :Foo, boxes) }.
|
||||||
|
to raise_error(Vagrant::Errors::ProviderNotFoundSuggestion)
|
||||||
|
end
|
||||||
|
|
||||||
it "raises an error if the provider is not usable" do
|
it "raises an error if the provider is not usable" do
|
||||||
register_provider("foo", nil, unusable: true)
|
register_provider("foo", nil, unusable: true)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue