From d1962b5bb6ee119610535b6dcd8efe8e986c434a Mon Sep 17 00:00:00 2001 From: Sam Alba Date: Mon, 12 Jul 2021 13:05:52 +0200 Subject: [PATCH] cmd/input: validate cue code with new inputs before persisting to the workspace Signed-off-by: Sam Alba --- cmd/dagger/cmd/edit.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/cmd/dagger/cmd/edit.go b/cmd/dagger/cmd/edit.go index cfcf032b..cb8e0fc2 100644 --- a/cmd/dagger/cmd/edit.go +++ b/cmd/dagger/cmd/edit.go @@ -9,6 +9,8 @@ import ( "go.dagger.io/dagger/cmd/dagger/cmd/common" "go.dagger.io/dagger/cmd/dagger/logger" + "go.dagger.io/dagger/environment" + "go.dagger.io/dagger/solver" "go.dagger.io/dagger/state" "github.com/google/shlex" @@ -67,6 +69,21 @@ var editCmd = &cobra.Command{ st.Name = newState.Name st.Plan = newState.Plan st.Inputs = newState.Inputs + + cl := common.NewClient(ctx) + _, err = cl.Do(ctx, st, func(ctx context.Context, env *environment.Environment, s solver.Solver) error { + // check for cue errors by scanning all the inputs + _, err := env.ScanInputs(ctx, true) + if err != nil { + return err + } + return nil + }) + + if err != nil { + lg.Fatal().Err(err).Str("environment", st.Name).Msg("invalid input") + } + if err := workspace.Save(ctx, st); err != nil { lg.Fatal().Err(err).Msg("failed to save state") }