Use common rpc errdetails messages

This commit is contained in:
sophia 2022-01-11 11:44:35 -06:00 committed by Paul Hinze
parent df5f7d40e8
commit deb667ecd3
No known key found for this signature in database
GPG Key ID: B69DEDF2D55501C0
4 changed files with 6 additions and 12 deletions

View File

@ -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 {

View File

@ -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())
}
}

View File

@ -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

View File

@ -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
)
)