Skip to content

Commit

Permalink
Re-export FieldPathString (#181)
Browse files Browse the repository at this point in the history
It turns out we wind up needing this function quite a lot (e.g. it's
used in Buf CLI) and I've gotten feedback that it is important for many
uses. We'll need an equivalent public function for this in each runtime.
  • Loading branch information
jchadwick-buf authored Jan 31, 2025
1 parent 81b747c commit 4459217
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 2 additions & 2 deletions error_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,9 @@ func finalizeViolationPaths(err error) {
}
}

// fieldPathString takes a FieldPath and encodes it to a string-based dotted
// FieldPathString takes a FieldPath and encodes it to a string-based dotted
// field path.
func fieldPathString(path []*validate.FieldPathElement) string {
func FieldPathString(path []*validate.FieldPathElement) string {
var result strings.Builder
for i, element := range path {
if i > 0 {
Expand Down
2 changes: 1 addition & 1 deletion validation_error.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func (err *ValidationError) Error() string {
bldr.WriteString("validation error:")
for _, violation := range err.Violations {
bldr.WriteString("\n - ")
if fieldPath := fieldPathString(violation.Proto.GetField().GetElements()); fieldPath != "" {
if fieldPath := FieldPathString(violation.Proto.GetField().GetElements()); fieldPath != "" {
bldr.WriteString(fieldPath)
bldr.WriteString(": ")
}
Expand Down

0 comments on commit 4459217

Please sign in to comment.