From 22fb218b28c0136e1b3360ae6615f578e3c28c26 Mon Sep 17 00:00:00 2001 From: Andrea Luzzardi Date: Thu, 14 Jan 2021 17:52:39 -0800 Subject: [PATCH] component: do not fail if `#dagger` marker has no compute Signed-off-by: Andrea Luzzardi --- dagger/component.go | 11 ++++++++++- dagger/script.go | 2 +- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/dagger/component.go b/dagger/component.go index 6acdeb21..874d1512 100644 --- a/dagger/component.go +++ b/dagger/component.go @@ -2,6 +2,7 @@ package dagger import ( "context" + "os" ) type Component struct { @@ -37,7 +38,11 @@ func (c *Component) Validate() error { // Return this component's compute script. func (c *Component) ComputeScript() (*Script, error) { - return c.Value().Get("#dagger.compute").Script() + v := c.Value().Get("#dagger.compute") + if !v.Exists() { + return nil, os.ErrNotExist + } + return v.Script() } // Compute the configuration for this component. @@ -62,6 +67,10 @@ func (c *Component) Compute(ctx context.Context, s Solver, out Fillable) (FS, er func (c *Component) Execute(ctx context.Context, fs FS, out Fillable) (FS, error) { script, err := c.ComputeScript() if err != nil { + // If the component has no script, then do not fail. + if os.IsNotExist(err) { + return fs, nil + } return fs, err } return script.Execute(ctx, fs, out) diff --git a/dagger/script.go b/dagger/script.go index b15752f5..03b6ce11 100644 --- a/dagger/script.go +++ b/dagger/script.go @@ -10,7 +10,7 @@ type Script struct { v *Value } -func (s Script) Validate() error { +func (s *Script) Validate() error { // FIXME this crashes when a script is incomplete or empty return s.Value().Validate("#Script") }