diff --git a/internal/cli/dynamic.go b/internal/cli/dynamic.go index 3c1e0321f..bbc630a97 100644 --- a/internal/cli/dynamic.go +++ b/internal/cli/dynamic.go @@ -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) diff --git a/plugins/commands/serve/util/exception_logger.rb b/plugins/commands/serve/util/exception_logger.rb index ce0b2c235..b9de613fc 100644 --- a/plugins/commands/serve/util/exception_logger.rb +++ b/plugins/commands/serve/util/exception_logger.rb @@ -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'