cmd/input: validate cue code with new inputs before persisting to the workspace

Signed-off-by: Sam Alba <sam.alba@gmail.com>
This commit is contained in:
Sam Alba 2021-07-12 13:05:52 +02:00
parent 9f907fea62
commit d1962b5bb6

View File

@ -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")
}