core: better error when adding box with malformed version [GH-3332]
This commit is contained in:
parent
12f73a949a
commit
097dd2917c
|
@ -21,6 +21,7 @@ BUG FIXES:
|
||||||
- core: Can add boxes with spaces in their path. [GH-3306]
|
- core: Can add boxes with spaces in their path. [GH-3306]
|
||||||
- core: Prerelease plugins installed are locked to that prerelease
|
- core: Prerelease plugins installed are locked to that prerelease
|
||||||
version. [GH-3301]
|
version. [GH-3301]
|
||||||
|
- core: Better error message when adding a box with a malformed version. [GH-3332]
|
||||||
- commands/box: Show versions when listing. [GH-3316]
|
- commands/box: Show versions when listing. [GH-3316]
|
||||||
- commands/status: Machine readable output contains the target. [GH-3218]
|
- commands/status: Machine readable output contains the target. [GH-3218]
|
||||||
- guests/arch: Reload udev rules after network change. [GH-3322]
|
- guests/arch: Reload udev rules after network change. [GH-3322]
|
||||||
|
|
|
@ -31,12 +31,14 @@ module Vagrant
|
||||||
@name = @raw["name"]
|
@name = @raw["name"]
|
||||||
@description = @raw["description"]
|
@description = @raw["description"]
|
||||||
@version_map = (@raw["versions"] || []).map do |v|
|
@version_map = (@raw["versions"] || []).map do |v|
|
||||||
[Gem::Version.new(v["version"]), v]
|
begin
|
||||||
|
[Gem::Version.new(v["version"]), v]
|
||||||
|
rescue ArgumentError
|
||||||
|
raise Errors::BoxMetadataMalformedVersion,
|
||||||
|
version: v["version"].to_s
|
||||||
|
end
|
||||||
end
|
end
|
||||||
@version_map = Hash[@version_map]
|
@version_map = Hash[@version_map]
|
||||||
|
|
||||||
# TODO: check for corruption:
|
|
||||||
# - malformed version
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# Returns data about a single version that is included in this
|
# Returns data about a single version that is included in this
|
||||||
|
|
|
@ -172,6 +172,10 @@ module Vagrant
|
||||||
error_key(:box_metadata_malformed)
|
error_key(:box_metadata_malformed)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
class BoxMetadataMalformedVersion < VagrantError
|
||||||
|
error_key(:box_metadata_malformed_version)
|
||||||
|
end
|
||||||
|
|
||||||
class BoxNotFound < VagrantError
|
class BoxNotFound < VagrantError
|
||||||
error_key(:box_not_found)
|
error_key(:box_not_found)
|
||||||
end
|
end
|
||||||
|
|
|
@ -392,6 +392,11 @@ en:
|
||||||
that this issue can be fixed.
|
that this issue can be fixed.
|
||||||
|
|
||||||
%{error}
|
%{error}
|
||||||
|
box_metadata_malformed_version: |-
|
||||||
|
A version of the box you're loading is formatted in a way that
|
||||||
|
Vagrant cannot parse: '%{version}'. Please reformat the version
|
||||||
|
to be properly formatted. It should be in the format of
|
||||||
|
X.Y.Z.
|
||||||
box_not_found: |-
|
box_not_found: |-
|
||||||
The box '%{name}' does not exist. Please double check and
|
The box '%{name}' does not exist. Please double check and
|
||||||
try again. You can see the boxes that are installed with
|
try again. You can see the boxes that are installed with
|
||||||
|
|
|
@ -61,6 +61,25 @@ describe Vagrant::BoxMetadata do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context "with poorly formatted version" do
|
||||||
|
let(:raw) {
|
||||||
|
<<-RAW
|
||||||
|
{ "name": "foo",
|
||||||
|
"versions": [
|
||||||
|
{
|
||||||
|
"version": "I AM NOT VALID"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
RAW
|
||||||
|
}
|
||||||
|
|
||||||
|
it "raises an exception" do
|
||||||
|
expect { subject }.
|
||||||
|
to raise_error(Vagrant::Errors::BoxMetadataMalformedVersion)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
describe "#version" do
|
describe "#version" do
|
||||||
it "matches an exact version" do
|
it "matches an exact version" do
|
||||||
result = subject.version("1.0.0")
|
result = subject.version("1.0.0")
|
||||||
|
|
Loading…
Reference in New Issue