2020-10-28 21:07:44 +00:00
|
|
|
package errdefs
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/moby/buildkit/solver"
|
|
|
|
)
|
|
|
|
|
|
|
|
// ExecError will be returned when an error is encountered when evaluating an op.
|
|
|
|
type ExecError struct {
|
|
|
|
error
|
2020-11-14 07:20:41 +00:00
|
|
|
Inputs []solver.Result
|
|
|
|
Mounts []solver.Result
|
2020-10-28 21:07:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (e *ExecError) Unwrap() error {
|
|
|
|
return e.error
|
|
|
|
}
|
|
|
|
|
|
|
|
func (e *ExecError) EachRef(fn func(solver.Result) error) (err error) {
|
|
|
|
for _, res := range e.Inputs {
|
2020-11-14 07:20:41 +00:00
|
|
|
if res == nil {
|
|
|
|
continue
|
|
|
|
}
|
2020-10-28 21:07:44 +00:00
|
|
|
if err1 := fn(res); err1 != nil && err == nil {
|
|
|
|
err = err1
|
|
|
|
}
|
|
|
|
}
|
2020-11-14 07:20:41 +00:00
|
|
|
for _, res := range e.Mounts {
|
|
|
|
if res == nil {
|
|
|
|
continue
|
|
|
|
}
|
2020-10-28 21:07:44 +00:00
|
|
|
if err1 := fn(res); err1 != nil && err == nil {
|
|
|
|
err = err1
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2020-11-14 07:20:41 +00:00
|
|
|
func WithExecError(err error, inputs, mounts []solver.Result) error {
|
2020-10-28 21:07:44 +00:00
|
|
|
if err == nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
return &ExecError{
|
2020-11-14 07:20:41 +00:00
|
|
|
error: err,
|
|
|
|
Inputs: inputs,
|
|
|
|
Mounts: mounts,
|
2020-10-28 21:07:44 +00:00
|
|
|
}
|
|
|
|
}
|