Merge pull request #285 from hashicorp/improve-run-operation-error-handling

Improve run operation error handling
This commit is contained in:
Paul Hinze 2022-06-10 13:04:43 -05:00 committed by GitHub
commit 94caf200e8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -2,9 +2,12 @@ package runner
import (
"context"
"fmt"
"github.com/hashicorp/vagrant/internal/core"
"github.com/hashicorp/vagrant/internal/server/proto/vagrant_server"
"google.golang.org/genproto/googleapis/rpc/status"
"google.golang.org/grpc/codes"
)
type Runs interface {
@ -35,10 +38,18 @@ func (r *Runner) executeRunOp(
jrr.RunResult = err == nil
if err != nil {
jrr.RunError = err.(core.CommandError).Status()
if cmdErr, ok := err.(core.CommandError); ok {
jrr.RunError = err.(core.CommandError).Status()
jrr.ExitCode = int32(cmdErr.ExitCode())
} else {
// If we have an error without a status we'll make one here
jrr.RunError = &status.Status{
Code: int32(codes.Unknown),
Message: fmt.Sprintf("Unexpected error from run operation: %s", err),
}
jrr.ExitCode = 1
}
}
r.logger.Info("run operation is complete!")