Pass error status with job completion results
This commit is contained in:
parent
d09c12dad3
commit
aeda0ec039
@ -2,16 +2,20 @@ package core
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"google.golang.org/genproto/googleapis/rpc/status"
|
||||
)
|
||||
|
||||
type CommandError interface {
|
||||
error
|
||||
ExitCode() int32
|
||||
Status() *status.Status
|
||||
}
|
||||
|
||||
type runError struct {
|
||||
err error
|
||||
exitCode int32
|
||||
status *status.Status
|
||||
}
|
||||
|
||||
// Error implements error
|
||||
@ -22,6 +26,12 @@ func (r *runError) Error() string {
|
||||
return fmt.Sprintf("non-zero exit code: %d", r.exitCode)
|
||||
}
|
||||
|
||||
// runError implements CommandError
|
||||
func (r *runError) ExitCode() int32 {
|
||||
return r.exitCode
|
||||
}
|
||||
|
||||
// runError implements CommandError
|
||||
func (r *runError) Status() *status.Status {
|
||||
return r.status
|
||||
}
|
||||
|
||||
@ -10,6 +10,7 @@ import (
|
||||
"github.com/hashicorp/go-argmapper"
|
||||
"github.com/hashicorp/go-hclog"
|
||||
"github.com/hashicorp/go-multierror"
|
||||
"google.golang.org/grpc/status"
|
||||
|
||||
"github.com/hashicorp/vagrant-plugin-sdk/component"
|
||||
"github.com/hashicorp/vagrant-plugin-sdk/core"
|
||||
@ -298,6 +299,9 @@ func (p *Project) Run(ctx context.Context, task *vagrant_server.Task) (err error
|
||||
cmdErr := &runError{}
|
||||
if err != nil {
|
||||
cmdErr.err = err
|
||||
if st, ok := status.FromError(err); ok {
|
||||
cmdErr.status = st.Proto()
|
||||
}
|
||||
}
|
||||
if result != nil {
|
||||
cmdErr.exitCode = result.(int32)
|
||||
|
||||
@ -3,8 +3,6 @@ package runner
|
||||
import (
|
||||
"context"
|
||||
|
||||
"google.golang.org/grpc/status"
|
||||
|
||||
"github.com/hashicorp/vagrant/internal/core"
|
||||
"github.com/hashicorp/vagrant/internal/server/proto/vagrant_server"
|
||||
)
|
||||
@ -37,8 +35,7 @@ func (r *Runner) executeRunOp(
|
||||
|
||||
jrr.RunResult = err == nil
|
||||
if err != nil {
|
||||
st, _ := status.FromError(err)
|
||||
jrr.RunError = st.Proto()
|
||||
jrr.RunError = err.(core.CommandError).Status()
|
||||
if cmdErr, ok := err.(core.CommandError); ok {
|
||||
jrr.ExitCode = int32(cmdErr.ExitCode())
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user