mirror of
https://github.com/hashicorp/vagrant.git
synced 2026-05-28 04:36:05 -04:00
Send localized message originating from plugin (if applicable)
This commit is contained in:
parent
45e64b9890
commit
c4e97bb89b
2 changed files with 17 additions and 4 deletions
|
|
@ -2,12 +2,13 @@ package cli
|
|||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"reflect"
|
||||
"strconv"
|
||||
|
||||
"github.com/DavidGamba/go-getoptions"
|
||||
"github.com/DavidGamba/go-getoptions/option"
|
||||
"google.golang.org/grpc/status"
|
||||
|
||||
"github.com/hashicorp/vagrant-plugin-sdk/proto/vagrant_plugin_sdk"
|
||||
"github.com/hashicorp/vagrant-plugin-sdk/terminal"
|
||||
|
|
@ -94,8 +95,13 @@ func (c *DynamicCommand) Run(args []string) int {
|
|||
cl.UI().Output("Running of task "+c.name+" failed unexpectedly\n", terminal.WithErrorStyle())
|
||||
cl.UI().Output("Error: "+err.Error(), terminal.WithErrorStyle())
|
||||
} else if !r.RunResult {
|
||||
cl.UI().Output("Error: "+r.RunError.Message+"\n", terminal.WithErrorStyle())
|
||||
err = errors.New("execution failed")
|
||||
runErrorStatus := status.FromProto(r.RunError)
|
||||
details := runErrorStatus.Details()
|
||||
// TODO: seach through the details for a localized message if exists
|
||||
userMessage := details[0].(*vagrant_plugin_sdk.Errors_LocalizedErrorMessage).Message
|
||||
cl.UI().Output("Error: "+userMessage+"\n", terminal.WithErrorStyle())
|
||||
runErr := status.FromProto(r.RunError)
|
||||
err = fmt.Errorf("execution failed, %w", runErr.Err())
|
||||
}
|
||||
|
||||
c.Log.Debug("result from operation", "task", c.name, "result", r)
|
||||
|
|
|
|||
|
|
@ -17,10 +17,17 @@ module VagrantPlugins
|
|||
begin
|
||||
super(*args, **opts, &block)
|
||||
rescue => err
|
||||
localized_msg_details_any = Google::Protobuf::Any.new
|
||||
localized_msg_details_any.pack(
|
||||
SDK::Errors::LocalizedErrorMessage.new(
|
||||
locale: "en-US", message: err.message
|
||||
)
|
||||
)
|
||||
|
||||
proto = Google::Rpc::Status.new(
|
||||
code: GRPC::Core::StatusCodes::UNKNOWN,
|
||||
message: "#{err.message}\n#{err.backtrace.join("\n")}",
|
||||
details: [mapper.map(err.message, to: Google::Protobuf::Any)]
|
||||
details: [localized_msg_details_any]
|
||||
)
|
||||
encoded_proto = Google::Rpc::Status.encode(proto)
|
||||
grpc_status_details_bin_trailer = 'grpc-status-details-bin'
|
||||
|
|
|
|||
Loading…
Reference in a new issue