From deb667ecd3c875d854a98ee674fba436a3ef9014 Mon Sep 17 00:00:00 2001 From: sophia Date: Tue, 11 Jan 2022 11:44:35 -0600 Subject: [PATCH] Use common rpc errdetails messages --- builtin/myplugin/host/alwaystrue.go | 4 ++-- internal/cli/dynamic.go | 3 ++- .../protobufs/proto/vagrant_plugin_sdk/plugin_pb.rb | 9 +-------- plugins/commands/serve/util/exception_transformer.rb | 2 +- 4 files changed, 6 insertions(+), 12 deletions(-) diff --git a/builtin/myplugin/host/alwaystrue.go b/builtin/myplugin/host/alwaystrue.go index a53088781..a8cb8d24c 100644 --- a/builtin/myplugin/host/alwaystrue.go +++ b/builtin/myplugin/host/alwaystrue.go @@ -1,7 +1,7 @@ package host import ( - "errors" + "fmt" "github.com/hashicorp/vagrant-plugin-sdk/component" "github.com/hashicorp/vagrant-plugin-sdk/terminal" @@ -61,7 +61,7 @@ func (h *AlwaysTrueHost) CapabilityFunc(name string) interface{} { } else if name == "write_hello_file" { return h.WriteHelloToTempFileCap } - return errors.New("Invalid capability requested") + return fmt.Errorf("requested capability %s not found", name) } func (h *AlwaysTrueHost) WriteHelloCap(ui terminal.UI) error { diff --git a/internal/cli/dynamic.go b/internal/cli/dynamic.go index fba7cb98f..02ee51e5a 100644 --- a/internal/cli/dynamic.go +++ b/internal/cli/dynamic.go @@ -8,6 +8,7 @@ import ( "github.com/DavidGamba/go-getoptions" "github.com/DavidGamba/go-getoptions/option" + "google.golang.org/genproto/googleapis/rpc/errdetails" "google.golang.org/grpc/status" "github.com/hashicorp/vagrant-plugin-sdk/proto/vagrant_plugin_sdk" @@ -99,7 +100,7 @@ func (c *DynamicCommand) Run(args []string) int { details := runErrorStatus.Details() for _, msg := range details { switch m := msg.(type) { - case *vagrant_plugin_sdk.Errors_LocalizedErrorMessage: + case *errdetails.LocalizedMessage: cl.UI().Output("Error: "+m.Message+"\n", terminal.WithErrorStyle()) } } diff --git a/lib/vagrant/protobufs/proto/vagrant_plugin_sdk/plugin_pb.rb b/lib/vagrant/protobufs/proto/vagrant_plugin_sdk/plugin_pb.rb index 47e478ecd..35db15ad0 100644 --- a/lib/vagrant/protobufs/proto/vagrant_plugin_sdk/plugin_pb.rb +++ b/lib/vagrant/protobufs/proto/vagrant_plugin_sdk/plugin_pb.rb @@ -8,15 +8,10 @@ require 'google/protobuf/timestamp_pb' require 'google/protobuf/empty_pb' require 'google/protobuf/struct_pb' require 'google/rpc/status_pb' +require 'google/rpc/error_details_pb' require 'protostructure_pb' Google::Protobuf::DescriptorPool.generated_pool.build do add_file("vagrant_plugin_sdk/plugin.proto", :syntax => :proto3) do - add_message "hashicorp.vagrant.sdk.Errors" do - end - add_message "hashicorp.vagrant.sdk.Errors.LocalizedErrorMessage" do - optional :locale, :string, 1 - optional :message, :string, 2 - end add_message "hashicorp.vagrant.sdk.Args" do end add_message "hashicorp.vagrant.sdk.Args.Seeds" do @@ -843,8 +838,6 @@ end module Hashicorp module Vagrant module Sdk - Errors = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("hashicorp.vagrant.sdk.Errors").msgclass - Errors::LocalizedErrorMessage = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("hashicorp.vagrant.sdk.Errors.LocalizedErrorMessage").msgclass Args = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("hashicorp.vagrant.sdk.Args").msgclass Args::Seeds = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("hashicorp.vagrant.sdk.Args.Seeds").msgclass Args::DataDir = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("hashicorp.vagrant.sdk.Args.DataDir").msgclass diff --git a/plugins/commands/serve/util/exception_transformer.rb b/plugins/commands/serve/util/exception_transformer.rb index db0522e9f..23ec9cd6a 100644 --- a/plugins/commands/serve/util/exception_transformer.rb +++ b/plugins/commands/serve/util/exception_transformer.rb @@ -22,7 +22,7 @@ module VagrantPlugins end localized_msg_details_any = Google::Protobuf::Any.new localized_msg_details_any.pack( - SDK::Errors::LocalizedErrorMessage.new( + Google::Rpc::LocalizedMessage.new( locale: "en-US", message: err.message ) )