Merge pull request #12898 from soapy1/pass-around-errors
Pass around errors
This commit is contained in:
commit
e753ea12d1
3
go.mod
3
go.mod
@ -25,7 +25,7 @@ require (
|
||||
github.com/hashicorp/go-version v1.3.0
|
||||
github.com/hashicorp/hcl/v2 v2.11.1
|
||||
github.com/hashicorp/nomad/api v0.0.0-20200814140818-42de70466a9d
|
||||
github.com/hashicorp/vagrant-plugin-sdk v0.0.0-20220919180525-50c632cd450d
|
||||
github.com/hashicorp/vagrant-plugin-sdk v0.0.0-20220919180735-d47bfe003e94
|
||||
github.com/imdario/mergo v0.3.11
|
||||
github.com/improbable-eng/grpc-web v0.13.0
|
||||
github.com/kr/text v0.2.0
|
||||
@ -94,6 +94,7 @@ require (
|
||||
github.com/go-git/gcfg v1.5.0 // indirect
|
||||
github.com/go-git/go-billy/v5 v5.0.0 // indirect
|
||||
github.com/go-test/deep v1.0.7 // indirect
|
||||
github.com/gogo/googleapis v1.4.1 // indirect
|
||||
github.com/gogo/protobuf v1.3.2 // indirect
|
||||
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
|
||||
github.com/golang/protobuf v1.5.2 // indirect
|
||||
|
||||
4
go.sum
4
go.sum
@ -209,6 +209,8 @@ github.com/go-test/deep v1.0.7 h1:/VSMRlnY/JSyqxQUzQLKVMAskpY/NZKFA5j2P+0pP2M=
|
||||
github.com/go-test/deep v1.0.7/go.mod h1:QV8Hv/iy04NyLBxAdO9njL0iVPN1S4d/A3NVv1V36o8=
|
||||
github.com/gofrs/flock v0.8.0 h1:MSdYClljsF3PbENUUEx85nkWfJSGfzYI9yEBZOJz6CY=
|
||||
github.com/gofrs/flock v0.8.0/go.mod h1:F1TvTiK9OcQqauNUHlbJvyl9Qa1QvF/gOUDKA14jxHU=
|
||||
github.com/gogo/googleapis v1.4.1 h1:1Yx4Myt7BxzvUr5ldGSbwYiZG6t9wGBZ+8/fX3Wvtq0=
|
||||
github.com/gogo/googleapis v1.4.1/go.mod h1:2lpHqI5OcWCtVElxXnPt+s8oJvMpySlOyM6xDCrzib4=
|
||||
github.com/gogo/protobuf v1.3.1/go.mod h1:SlYgWuQ5SjCEi6WLHjHCa1yvBfUnHcTbrrZtXPKa29o=
|
||||
github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q=
|
||||
github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q=
|
||||
@ -363,6 +365,8 @@ github.com/hashicorp/vagrant-plugin-sdk v0.0.0-20220913204040-793a2626f6f9 h1:wf
|
||||
github.com/hashicorp/vagrant-plugin-sdk v0.0.0-20220913204040-793a2626f6f9/go.mod h1:zA5vDskG3gH306C+obL+yURiUiLMAlx52yqO8MC2r9w=
|
||||
github.com/hashicorp/vagrant-plugin-sdk v0.0.0-20220919180525-50c632cd450d h1:TqCLroDhxzGMXE7LrgqDayOku2oRJ4vjROX7ghpzqsI=
|
||||
github.com/hashicorp/vagrant-plugin-sdk v0.0.0-20220919180525-50c632cd450d/go.mod h1:zA5vDskG3gH306C+obL+yURiUiLMAlx52yqO8MC2r9w=
|
||||
github.com/hashicorp/vagrant-plugin-sdk v0.0.0-20220919180735-d47bfe003e94 h1:CGq9dOg/kK0ihxx81H59xEHGfTvRs0ls8qCL3Bujdgo=
|
||||
github.com/hashicorp/vagrant-plugin-sdk v0.0.0-20220919180735-d47bfe003e94/go.mod h1:zA5vDskG3gH306C+obL+yURiUiLMAlx52yqO8MC2r9w=
|
||||
github.com/hashicorp/yamux v0.0.0-20180604194846-3520598351bb/go.mod h1:+NfK9FKeTrX5uv1uIXGdwYDTeHna2qgaIlx54MXqjAM=
|
||||
github.com/hashicorp/yamux v0.0.0-20200609203250-aecfd211c9ce h1:7UnVY3T/ZnHUrfviiAgIUjg2PXxsQfs5bphsG8F7Keo=
|
||||
github.com/hashicorp/yamux v0.0.0-20200609203250-aecfd211c9ce/go.mod h1:+NfK9FKeTrX5uv1uIXGdwYDTeHna2qgaIlx54MXqjAM=
|
||||
|
||||
@ -392,10 +392,7 @@ func (p *Project) DefaultProvider(opts *core.DefaultProviderOptions) (string, er
|
||||
if opts.CheckUsable {
|
||||
logger.Debug("Checking usable on provider", "provider", pp.Name)
|
||||
pluginImpl := plug.Plugin.(core.Provider)
|
||||
usable, err := pluginImpl.Usable()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
usable, _ := pluginImpl.Usable()
|
||||
if !usable {
|
||||
logger.Debug("Skipping unusable provider", "provider", pp.Name)
|
||||
continue
|
||||
|
||||
@ -9,6 +9,7 @@ import (
|
||||
"github.com/hashicorp/go-hclog"
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/status"
|
||||
|
||||
"google.golang.org/protobuf/proto"
|
||||
|
||||
"github.com/hashicorp/vagrant-plugin-sdk/component"
|
||||
@ -18,6 +19,7 @@ import (
|
||||
"github.com/hashicorp/vagrant-plugin-sdk/internal-shared/cleanup"
|
||||
"github.com/hashicorp/vagrant-plugin-sdk/internal-shared/dynamic"
|
||||
"github.com/hashicorp/vagrant-plugin-sdk/internal-shared/protomappers"
|
||||
"github.com/hashicorp/vagrant-plugin-sdk/localizer"
|
||||
"github.com/hashicorp/vagrant-plugin-sdk/proto/vagrant_plugin_sdk"
|
||||
"github.com/hashicorp/vagrant/internal/plugin"
|
||||
"github.com/hashicorp/vagrant/internal/server/proto/vagrant_server"
|
||||
@ -444,7 +446,7 @@ func (v *Vagrantfile) Target(
|
||||
return nil, err
|
||||
}
|
||||
|
||||
conf, err := v.TargetConfig(name, provider, false)
|
||||
conf, err := v.TargetConfig(name, provider, true)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
@ -456,6 +458,7 @@ func (v *Vagrantfile) Target(
|
||||
Project: v.targetSource,
|
||||
},
|
||||
),
|
||||
WithProvider(provider),
|
||||
}
|
||||
var vf *Vagrantfile
|
||||
|
||||
@ -468,12 +471,15 @@ func (v *Vagrantfile) Target(
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
rawTarget := target.(*Target)
|
||||
if provider != "" {
|
||||
rawTarget.target.Provider = provider
|
||||
}
|
||||
|
||||
// Since the target config gives us a Vagrantfile which is
|
||||
// attached to the project, we need to clone it and attach
|
||||
// it to the target we loaded
|
||||
if vf != nil {
|
||||
rawTarget := target.(*Target)
|
||||
tvf := vf.clone(name)
|
||||
|
||||
if err = tvf.Init(); err != nil {
|
||||
@ -492,7 +498,6 @@ func (v *Vagrantfile) Target(
|
||||
|
||||
// Generate a new Vagrantfile for the given target
|
||||
// NOTE: This function may return a nil result without an error
|
||||
// TODO(spox): Provider validation is not currently implemented
|
||||
// TODO(spox): Needs box configuration applied
|
||||
func (v *Vagrantfile) TargetConfig(
|
||||
name, // name of the target
|
||||
@ -507,6 +512,29 @@ func (v *Vagrantfile) TargetConfig(
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if provider != "" {
|
||||
pp, err := v.factory.plugins.Find(provider, component.ProviderType)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if validateProvider {
|
||||
usable, err := pp.Component.(core.Provider).Usable()
|
||||
if !usable {
|
||||
if errStatus, ok := status.FromError(err); ok {
|
||||
return nil, localizer.LocalizeStatusErr(
|
||||
"provider_not_usable",
|
||||
map[string]string{"Provider": provider, "Machine": name},
|
||||
errStatus,
|
||||
true,
|
||||
)
|
||||
}
|
||||
}
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
cid := name + "+" + provider
|
||||
if cv := v.cache.Get(cid); cv != nil {
|
||||
return cv.(core.Vagrantfile), nil
|
||||
|
||||
@ -25,7 +25,7 @@ module Vagrant
|
||||
client.target_names
|
||||
end
|
||||
|
||||
def machine_config(name, provider, _, _, validate_provider)
|
||||
def machine_config(name, provider, _, _, validate_provider=true)
|
||||
client.machine_config(name, provider, validate_provider)
|
||||
end
|
||||
end
|
||||
|
||||
@ -20,7 +20,7 @@ module VagrantPlugins
|
||||
|
||||
def usable(req, ctx)
|
||||
with_plugin(ctx, :providers, broker: broker) do |plugin|
|
||||
is_usable = plugin.usable?
|
||||
is_usable = plugin.usable?(true)
|
||||
SDK::Provider::UsableResp.new(
|
||||
is_usable: is_usable,
|
||||
)
|
||||
|
||||
@ -58,11 +58,12 @@ module VagrantPlugins
|
||||
if err.is_a? Vagrant::Errors::VagrantError
|
||||
localized_msg_details_any = Google::Protobuf::Any.new
|
||||
localized_msg_details_any.pack(
|
||||
Google::Rpc::LocalizedMessage.new(locale: "en-US", message: message)
|
||||
Google::Rpc::LocalizedMessage.new(locale: "en-US", message: message.gsub("\n", " "))
|
||||
)
|
||||
proto = Google::Rpc::Status.new(
|
||||
code: GRPC::Core::StatusCodes::UNKNOWN,
|
||||
details: [localized_msg_details_any]
|
||||
details: [localized_msg_details_any],
|
||||
message: message,
|
||||
)
|
||||
metadata[GRPC_DETAILS_METADATA_KEY] = Google::Rpc::Status.encode(proto)
|
||||
end
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user