refactored to handle errors better

Signed-off-by: Richard Jones <richard@dagger.io>
This commit is contained in:
Richard Jones 2021-12-14 14:28:29 -07:00
parent ceb1827526
commit e65b3cfa4a

View File

@ -19,8 +19,23 @@ type serviceTask struct {
}
func (c serviceTask) Run(ctx context.Context, pctx *plancontext.Context, s solver.Solver, v *compiler.Value) (*compiler.Value, error) {
unix, _ := v.LookupPath(cue.ParsePath("unix")).String()
npipe, _ := v.LookupPath(cue.ParsePath("npipe")).String()
var unix, npipe string
var stringErr error
unixV := v.Lookup("unix")
npipeV := v.Lookup("npipe")
if unixV.Exists() && unixV.IsConcrete() {
unix, stringErr = unixV.String()
}
if npipeV.Exists() && npipeV.IsConcrete() {
npipe, stringErr = npipeV.String()
}
if stringErr != nil {
return nil, stringErr
}
if unix == "" && npipe == "" {
return nil, errors.New("invalid service")