Skip to content

Commit

Permalink
more careful format string/quoting in validator messages
Browse files Browse the repository at this point in the history
  • Loading branch information
chrismarget-j committed Oct 21, 2024
1 parent 6709eee commit 78e3b24
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 16 deletions.
2 changes: 1 addition & 1 deletion apstra/apstra_validator/forbidden_when_value_is.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ func (o ForbiddenWhenValueIsValidator) Validate(ctx context.Context, req Forbidd
if o.Value.Equal(mpVal) {
resp.Diagnostics.Append(validatordiag.InvalidAttributeCombinationDiagnostic(
req.Path,
fmt.Sprintf("attribute %q must not be set when %q has value %s, got: %q", req.Path, mp, mpVal, req.ConfigValue),
fmt.Sprintf("attribute %q must not be set when %q has value %s, got: %s", req.Path, mp, mpVal, req.ConfigValue),
))
}
}
Expand Down
4 changes: 2 additions & 2 deletions apstra/apstra_validator/required_when_value_is.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ type RequiredWhenValueIsResponse struct {
}

func (o RequiredWhenValueIsValidator) Description(_ context.Context) string {
return fmt.Sprintf("Ensures that a value is supplied when attribute at %q has value %q", o.expression.String(), o.value)
return fmt.Sprintf("Ensures that a value is supplied when attribute at %s has value %s", o.expression.String(), o.value)
}

func (o RequiredWhenValueIsValidator) MarkdownDescription(ctx context.Context) string {
Expand Down Expand Up @@ -81,7 +81,7 @@ func (o RequiredWhenValueIsValidator) Validate(ctx context.Context, req Required
resp.Diagnostics.AddAttributeError(
req.Path,
"Missing required attribute",
fmt.Sprintf("Attribute %q required when %q has value %q.", req.Path, mp.String(), mpVal.String()),
fmt.Sprintf("Attribute %q required when %q has value %s.", req.Path, mp, mpVal),
)
}
}
Expand Down
4 changes: 2 additions & 2 deletions apstra/apstra_validator/required_when_value_null.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ type RequiredWhenValueNullResponse struct {
}

func (o RequiredWhenValueNullValidator) Description(_ context.Context) string {
return fmt.Sprintf("Ensures that a value is supplied when attribute at %q is null", o.expression.String())
return fmt.Sprintf("Ensures that a value is supplied when attribute at %s is null", o.expression.String())
}

func (o RequiredWhenValueNullValidator) MarkdownDescription(ctx context.Context) string {
Expand Down Expand Up @@ -84,7 +84,7 @@ func (o RequiredWhenValueNullValidator) Validate(ctx context.Context, req Requir
resp.Diagnostics.AddAttributeError(
req.Path,
"Missing required attribute",
fmt.Sprintf("Attribute %q required when attribute %q is null.", req.Path, mp.String()),
fmt.Sprintf("Attribute %q required when attribute %q is null.", req.Path, mp),
)
}
}
Expand Down
2 changes: 1 addition & 1 deletion apstra/apstra_validator/value_at_must_be.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ type valueAtMustBeValidatorResponse struct {
}

func (o valueAtMustBeValidator) Description(_ context.Context) string {
return fmt.Sprintf("element at %q must be: %q (null is %t)", o.expression, o.value.String(), o.nullOk)
return fmt.Sprintf("element at %q must be: %s (null is %t)", o.expression, o.value, o.nullOk)
}

func (o valueAtMustBeValidator) MarkdownDescription(ctx context.Context) string {
Expand Down
20 changes: 10 additions & 10 deletions apstra/apstra_validator/when_value_is.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func (o whenValueIsValidator) Description(ctx context.Context) string {
descriptions = append(descriptions, v.Description(ctx))
}

return fmt.Sprintf("element must satisfy all validations: %s becuase value is %q", strings.Join(descriptions, " + "), o.trigger)
return fmt.Sprintf("element must satisfy all validations: %s becuase value is %s", strings.Join(descriptions, " + "), o.trigger)
}

func (o whenValueIsValidator) MarkdownDescription(ctx context.Context) string {
Expand All @@ -78,7 +78,7 @@ func (o whenValueIsValidator) ValidateBool(ctx context.Context, req validator.Bo
for _, v := range o.boolValidators {
vResponse := new(validator.BoolResponse)
v.ValidateBool(ctx, req, vResponse)
utils.WrapEachDiagnostic(fmt.Sprintf("When attribute %s is %q", req.Path, o.trigger), vResponse.Diagnostics...)
utils.WrapEachDiagnostic(fmt.Sprintf("When attribute %s is %s", req.Path, o.trigger), vResponse.Diagnostics...)
resp.Diagnostics.Append(vResponse.Diagnostics...)
}
}
Expand All @@ -97,7 +97,7 @@ func (o whenValueIsValidator) ValidateFloat64(ctx context.Context, req validator
for _, v := range o.float64Validators {
vResponse := new(validator.Float64Response)
v.ValidateFloat64(ctx, req, vResponse)
utils.WrapEachDiagnostic(fmt.Sprintf("When attribute %s is %q", req.Path, o.trigger), vResponse.Diagnostics...)
utils.WrapEachDiagnostic(fmt.Sprintf("When attribute %s is %s", req.Path, o.trigger), vResponse.Diagnostics...)
resp.Diagnostics.Append(vResponse.Diagnostics...)
}
}
Expand All @@ -116,7 +116,7 @@ func (o whenValueIsValidator) ValidateInt64(ctx context.Context, req validator.I
for _, v := range o.int64Validators {
vResponse := new(validator.Int64Response)
v.ValidateInt64(ctx, req, vResponse)
utils.WrapEachDiagnostic(fmt.Sprintf("When attribute %s is %q", req.Path, o.trigger), vResponse.Diagnostics...)
utils.WrapEachDiagnostic(fmt.Sprintf("When attribute %s is %s", req.Path, o.trigger), vResponse.Diagnostics...)
resp.Diagnostics.Append(vResponse.Diagnostics...)
}
}
Expand All @@ -135,7 +135,7 @@ func (o whenValueIsValidator) ValidateList(ctx context.Context, req validator.Li
for _, v := range o.listValidators {
vResponse := new(validator.ListResponse)
v.ValidateList(ctx, req, vResponse)
utils.WrapEachDiagnostic(fmt.Sprintf("When attribute %s is %q", req.Path, o.trigger), vResponse.Diagnostics...)
utils.WrapEachDiagnostic(fmt.Sprintf("When attribute %s is %s", req.Path, o.trigger), vResponse.Diagnostics...)
resp.Diagnostics.Append(vResponse.Diagnostics...)
}
}
Expand All @@ -154,7 +154,7 @@ func (o whenValueIsValidator) ValidateMap(ctx context.Context, req validator.Map
for _, v := range o.mapValidators {
vResponse := new(validator.MapResponse)
v.ValidateMap(ctx, req, vResponse)
utils.WrapEachDiagnostic(fmt.Sprintf("When attribute %s is %q", req.Path, o.trigger), vResponse.Diagnostics...)
utils.WrapEachDiagnostic(fmt.Sprintf("When attribute %s is %s", req.Path, o.trigger), vResponse.Diagnostics...)
resp.Diagnostics.Append(vResponse.Diagnostics...)
}
}
Expand All @@ -173,7 +173,7 @@ func (o whenValueIsValidator) ValidateNumber(ctx context.Context, req validator.
for _, v := range o.numberValidators {
vResponse := new(validator.NumberResponse)
v.ValidateNumber(ctx, req, vResponse)
utils.WrapEachDiagnostic(fmt.Sprintf("When attribute %s is %q", req.Path, o.trigger), vResponse.Diagnostics...)
utils.WrapEachDiagnostic(fmt.Sprintf("When attribute %s is %s", req.Path, o.trigger), vResponse.Diagnostics...)
resp.Diagnostics.Append(vResponse.Diagnostics...)
}
}
Expand All @@ -192,7 +192,7 @@ func (o whenValueIsValidator) ValidateObject(ctx context.Context, req validator.
for _, v := range o.objectValidators {
vResponse := new(validator.ObjectResponse)
v.ValidateObject(ctx, req, vResponse)
utils.WrapEachDiagnostic(fmt.Sprintf("When attribute %s is %q", req.Path, o.trigger), vResponse.Diagnostics...)
utils.WrapEachDiagnostic(fmt.Sprintf("When attribute %s is %s", req.Path, o.trigger), vResponse.Diagnostics...)
resp.Diagnostics.Append(vResponse.Diagnostics...)
}
}
Expand All @@ -211,7 +211,7 @@ func (o whenValueIsValidator) ValidateSet(ctx context.Context, req validator.Set
for _, v := range o.setValidators {
vResponse := new(validator.SetResponse)
v.ValidateSet(ctx, req, vResponse)
utils.WrapEachDiagnostic(fmt.Sprintf("When attribute %s is %q", req.Path, o.trigger), vResponse.Diagnostics...)
utils.WrapEachDiagnostic(fmt.Sprintf("When attribute %s is %s", req.Path, o.trigger), vResponse.Diagnostics...)
resp.Diagnostics.Append(vResponse.Diagnostics...)
}
}
Expand All @@ -230,7 +230,7 @@ func (o whenValueIsValidator) ValidateString(ctx context.Context, req validator.
for _, v := range o.stringValidators {
vResponse := new(validator.StringResponse)
v.ValidateString(ctx, req, vResponse)
utils.WrapEachDiagnostic(fmt.Sprintf("When attribute %s is %q", req.Path, o.trigger), vResponse.Diagnostics...)
utils.WrapEachDiagnostic(fmt.Sprintf("When attribute %s is %s", req.Path, o.trigger), vResponse.Diagnostics...)
resp.Diagnostics.Append(vResponse.Diagnostics...)
}
}
Expand Down

0 comments on commit 78e3b24

Please sign in to comment.