Merge pull request #810 from samalba/edit-validation

input edit: validate cue code with new inputs before persisting to the workspace
This commit is contained in:
Sam Alba 2021-07-12 13:24:40 +02:00 committed by GitHub
commit 2b9e74db45
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -9,6 +9,8 @@ import (
"go.dagger.io/dagger/cmd/dagger/cmd/common" "go.dagger.io/dagger/cmd/dagger/cmd/common"
"go.dagger.io/dagger/cmd/dagger/logger" "go.dagger.io/dagger/cmd/dagger/logger"
"go.dagger.io/dagger/environment"
"go.dagger.io/dagger/solver"
"go.dagger.io/dagger/state" "go.dagger.io/dagger/state"
"github.com/google/shlex" "github.com/google/shlex"
@ -67,6 +69,21 @@ var editCmd = &cobra.Command{
st.Name = newState.Name st.Name = newState.Name
st.Plan = newState.Plan st.Plan = newState.Plan
st.Inputs = newState.Inputs 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 { if err := workspace.Save(ctx, st); err != nil {
lg.Fatal().Err(err).Msg("failed to save state") lg.Fatal().Err(err).Msg("failed to save state")
} }