Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix showing error message when validation fail #7509

Merged
merged 1 commit into from
Dec 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pkg/apis/pipeline/v1/result_validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func (tr TaskResult) validateValue(ctx context.Context) (errs *apis.FieldError)
return nil
}
if !config.FromContextOrDefaults(ctx).FeatureFlags.EnableStepActions {
return apis.ErrGeneric("feature flag %s should be set to true to fetch Results from Steps using StepActions.", config.EnableStepActions)
return apis.ErrGeneric(fmt.Sprintf("feature flag %s should be set to true to fetch Results from Steps using StepActions.", config.EnableStepActions))
}
if tr.Value.Type != ParamTypeString {
return &apis.FieldError{
Expand Down
3 changes: 1 addition & 2 deletions pkg/apis/pipeline/v1/result_validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,7 @@ func TestResultsValidateValueError(t *testing.T) {
},
enableStepActions: false,
expectedError: apis.FieldError{
Message: "feature flag %s should be set to true to fetch Results from Steps using StepActions.",
Paths: []string{"enable-step-actions"},
Message: "feature flag enable-step-actions should be set to true to fetch Results from Steps using StepActions.",
},
}, {
name: "invalid result value type array",
Expand Down
4 changes: 2 additions & 2 deletions pkg/apis/pipeline/v1/task_validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ func isCreateOrUpdateAndDiverged(ctx context.Context, s Step) bool {
func validateStep(ctx context.Context, s Step, names sets.String) (errs *apis.FieldError) {
if s.Ref != nil {
if !config.FromContextOrDefaults(ctx).FeatureFlags.EnableStepActions && isCreateOrUpdateAndDiverged(ctx, s) {
return apis.ErrGeneric("feature flag %s should be set to true to reference StepActions in Steps.", config.EnableStepActions)
return apis.ErrGeneric(fmt.Sprintf("feature flag %s should be set to true to reference StepActions in Steps.", config.EnableStepActions), "")
}
errs = errs.Also(s.Ref.Validate(ctx))
if s.Image != "" {
Expand Down Expand Up @@ -385,7 +385,7 @@ func validateStep(ctx context.Context, s Step, names sets.String) (errs *apis.Fi
}
if len(s.Results) > 0 {
if !config.FromContextOrDefaults(ctx).FeatureFlags.EnableStepActions && isCreateOrUpdateAndDiverged(ctx, s) {
return apis.ErrGeneric("feature flag %s should be set to true in order to use Results in Steps.", config.EnableStepActions)
return apis.ErrGeneric(fmt.Sprintf("feature flag %s should be set to true in order to use Results in Steps.", config.EnableStepActions), "")
}
}
if s.Image == "" {
Expand Down
16 changes: 8 additions & 8 deletions pkg/apis/pipeline/v1/task_validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1429,8 +1429,8 @@ func TestTaskSpecValidateErrorWithStepActionRef_CreateUpdateEvent(t *testing.T)
isCreate: true,
isUpdate: false,
expectedError: apis.FieldError{
Message: "feature flag %s should be set to true to reference StepActions in Steps.",
Paths: []string{"steps[0].enable-step-actions"},
Message: "feature flag enable-step-actions should be set to true to reference StepActions in Steps.",
Paths: []string{"steps[0]"},
},
}, {
name: "is update ctx",
Expand All @@ -1442,8 +1442,8 @@ func TestTaskSpecValidateErrorWithStepActionRef_CreateUpdateEvent(t *testing.T)
isCreate: false,
isUpdate: true,
expectedError: apis.FieldError{
Message: "feature flag %s should be set to true to reference StepActions in Steps.",
Paths: []string{"steps[0].enable-step-actions"},
Message: "feature flag enable-step-actions should be set to true to reference StepActions in Steps.",
Paths: []string{"steps[0]"},
},
}, {
name: "ctx is not create or update",
Expand Down Expand Up @@ -2642,8 +2642,8 @@ func TestTaskSpecValidate_StepResults_Error(t *testing.T) {
enableStepActions: false,
isCreate: true,
expectedError: apis.FieldError{
Message: "feature flag %s should be set to true in order to use Results in Steps.",
Paths: []string{"steps[0].enable-step-actions"},
Message: "feature flag enable-step-actions should be set to true in order to use Results in Steps.",
Paths: []string{"steps[0]"},
},
}, {
name: "step result not allowed without enable step actions - update and diverged event",
Expand All @@ -2664,8 +2664,8 @@ func TestTaskSpecValidate_StepResults_Error(t *testing.T) {
},
},
expectedError: apis.FieldError{
Message: "feature flag %s should be set to true in order to use Results in Steps.",
Paths: []string{"steps[0].enable-step-actions"},
Message: "feature flag enable-step-actions should be set to true in order to use Results in Steps.",
Paths: []string{"steps[0]"},
},
}, {
name: "step result allowed without enable step actions - update but not diverged",
Expand Down
4 changes: 2 additions & 2 deletions pkg/apis/pipeline/v1beta1/result_validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func (tr TaskResult) validateValue(ctx context.Context) (errs *apis.FieldError)
return nil
}
if !config.FromContextOrDefaults(ctx).FeatureFlags.EnableStepActions {
return apis.ErrGeneric("feature flag %s should be set to true to fetch Results from Steps using StepActions.", config.EnableStepActions)
return apis.ErrGeneric(fmt.Sprintf("feature flag %s should be set to true to fetch Results from Steps using StepActions.", config.EnableStepActions))
}
if tr.Value.Type != ParamTypeString {
return &apis.FieldError{
Expand All @@ -89,7 +89,7 @@ func (tr TaskResult) validateValue(ctx context.Context) (errs *apis.FieldError)
stepName, resultName, err := v1.ExtractStepResultName(tr.Value.StringVal)
if err != nil {
return &apis.FieldError{
Message: fmt.Sprintf("%v", err),
Message: err.Error(),
Paths: []string{fmt.Sprintf("%s.value", tr.Name)},
}
}
Expand Down
3 changes: 1 addition & 2 deletions pkg/apis/pipeline/v1beta1/result_validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,7 @@ func TestResultsValidateValueError(t *testing.T) {
},
enableStepActions: false,
expectedError: apis.FieldError{
Message: "feature flag %s should be set to true to fetch Results from Steps using StepActions.",
Paths: []string{"enable-step-actions"},
Message: "feature flag enable-step-actions should be set to true to fetch Results from Steps using StepActions.",
},
}, {
name: "invalid result value type array",
Expand Down
4 changes: 2 additions & 2 deletions pkg/apis/pipeline/v1beta1/task_validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ func isCreateOrUpdateAndDiverged(ctx context.Context, s Step) bool {
func validateStep(ctx context.Context, s Step, names sets.String) (errs *apis.FieldError) {
if s.Ref != nil {
if !config.FromContextOrDefaults(ctx).FeatureFlags.EnableStepActions && isCreateOrUpdateAndDiverged(ctx, s) {
return apis.ErrGeneric("feature flag %s should be set to true to reference StepActions in Steps.", config.EnableStepActions)
return apis.ErrGeneric(fmt.Sprintf("feature flag %s should be set to true to reference StepActions in Steps.", config.EnableStepActions), "")
}
errs = errs.Also(s.Ref.Validate(ctx))
if s.Image != "" {
Expand Down Expand Up @@ -374,7 +374,7 @@ func validateStep(ctx context.Context, s Step, names sets.String) (errs *apis.Fi
}
if len(s.Results) > 0 {
if !config.FromContextOrDefaults(ctx).FeatureFlags.EnableStepActions && isCreateOrUpdateAndDiverged(ctx, s) {
return apis.ErrGeneric("feature flag %s should be set to true in order to use Results in Steps.", config.EnableStepActions)
return apis.ErrGeneric(fmt.Sprintf("feature flag %s should be set to true in order to use Results in Steps.", config.EnableStepActions), "")
}
}
if s.Image == "" {
Expand Down
16 changes: 8 additions & 8 deletions pkg/apis/pipeline/v1beta1/task_validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1442,8 +1442,8 @@ func TestTaskSpecValidateErrorWithStepActionRef_CreateUpdateEvent(t *testing.T)
isCreate: true,
isUpdate: false,
expectedError: apis.FieldError{
Message: "feature flag %s should be set to true to reference StepActions in Steps.",
Paths: []string{"steps[0].enable-step-actions"},
Message: "feature flag enable-step-actions should be set to true to reference StepActions in Steps.",
Paths: []string{"steps[0]"},
},
}, {
name: "is update ctx",
Expand All @@ -1455,8 +1455,8 @@ func TestTaskSpecValidateErrorWithStepActionRef_CreateUpdateEvent(t *testing.T)
isCreate: false,
isUpdate: true,
expectedError: apis.FieldError{
Message: "feature flag %s should be set to true to reference StepActions in Steps.",
Paths: []string{"steps[0].enable-step-actions"},
Message: "feature flag enable-step-actions should be set to true to reference StepActions in Steps.",
Paths: []string{"steps[0]"},
},
}, {
name: "ctx is not create or update",
Expand Down Expand Up @@ -2428,8 +2428,8 @@ func TestTaskSpecValidate_StepResults_Error(t *testing.T) {
enableStepActions: false,
isCreate: true,
expectedError: apis.FieldError{
Message: "feature flag %s should be set to true in order to use Results in Steps.",
Paths: []string{"steps[0].enable-step-actions"},
Message: "feature flag enable-step-actions should be set to true in order to use Results in Steps.",
Paths: []string{"steps[0]"},
},
}, {
name: "step result not allowed without enable step actions - update and diverged event",
Expand All @@ -2450,8 +2450,8 @@ func TestTaskSpecValidate_StepResults_Error(t *testing.T) {
},
},
expectedError: apis.FieldError{
Message: "feature flag %s should be set to true in order to use Results in Steps.",
Paths: []string{"steps[0].enable-step-actions"},
Message: "feature flag enable-step-actions should be set to true in order to use Results in Steps.",
Paths: []string{"steps[0]"},
},
}, {
name: "step result allowed without enable step actions - update but not diverged",
Expand Down
Loading