Skip to content

Commit 25531d1

Browse files
authored
Merge branch 'main' into tstamm/Delete-the---strict-flag-of-the-conformance-runner
2 parents 7780c49 + 51b65b6 commit 25531d1

File tree

1 file changed

+24
-14
lines changed
  • tools/protovalidate-conformance/internal/results

1 file changed

+24
-14
lines changed

tools/protovalidate-conformance/internal/results/result.go

+24-14
Original file line numberDiff line numberDiff line change
@@ -109,23 +109,33 @@ func Violations(violations ...*validate.Violation) Result {
109109

110110
func (v violationsResult) String() string {
111111
bldr := &strings.Builder{}
112-
errs := v.inner.GetValidationError().GetViolations()
113-
_, _ = fmt.Fprintf(bldr, "%d validation error(s)", len(errs))
114-
for i, err := range errs {
115-
forKey := ""
116-
if err.GetForKey() {
117-
forKey = " (key)"
112+
violations := v.inner.GetValidationError().GetViolations()
113+
if len(violations) == 1 {
114+
_, _ = fmt.Fprintf(bldr, "validation error (%d violation)", len(violations))
115+
} else {
116+
_, _ = fmt.Fprintf(bldr, "validation error (%d violations)", len(violations))
117+
}
118+
for i, violation := range violations {
119+
_, _ = fmt.Fprintf(bldr, "\n%s %2d. constraint_id: ", resultPadding, i+1)
120+
if violation.ConstraintId == nil {
121+
bldr.WriteString("<nil>")
122+
} else {
123+
_, _ = fmt.Fprintf(bldr, "%#v", violation.GetConstraintId())
124+
}
125+
if violation.Message != nil {
126+
_, _ = fmt.Fprintf(bldr, "\n%s message: %#v", resultPadding, violation.GetMessage())
127+
}
128+
//nolint:protogetter
129+
if violation.Field != nil {
130+
_, _ = fmt.Fprintf(bldr, "\n%s field: %#v %s", resultPadding, fieldpath.Marshal(violation.GetField()), violation.GetField())
118131
}
119-
violationPath := ""
120-
if path := err.GetField(); path != nil {
121-
violationPath = fieldpath.Marshal(path)
132+
if violation.ForKey != nil {
133+
_, _ = fmt.Fprintf(bldr, "\n%s for_key: %v", resultPadding, violation.GetForKey())
122134
}
123-
rulePath := ""
124-
if path := err.GetRule(); path != nil {
125-
rulePath = " (" + fieldpath.Marshal(path) + ")"
135+
//nolint:protogetter
136+
if violation.Rule != nil {
137+
_, _ = fmt.Fprintf(bldr, "\n%s rule: %#v %s", resultPadding, fieldpath.Marshal(violation.GetRule()), violation.GetRule())
126138
}
127-
_, _ = fmt.Fprintf(bldr, "\n%s %2d. %s%s: %s%s", resultPadding, i+1, violationPath, forKey, err.GetConstraintId(), rulePath)
128-
_, _ = fmt.Fprintf(bldr, "\n%s %s", resultPadding, err.GetMessage())
129139
}
130140
return bldr.String()
131141
}

0 commit comments

Comments
 (0)