Skip to content

Commit d021bd5

Browse files
committed
Improve error message for unknown fields
1 parent cf0a304 commit d021bd5

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

internal/constraints/cache.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ func (c *Cache) Build(
6363
return nil, errors.NewCompilationErrorf("error reparsing message: %w", err)
6464
}
6565
if !allowUnknownFields && len(constraints.GetUnknown()) > 0 {
66-
return nil, errors.NewCompilationErrorf("unknown constraints in %s", constraints.Descriptor().FullName())
66+
return nil, errors.NewCompilationErrorf("unknown constraints in %s; see protovalidate.WithExtensionTypeResolver", constraints.Descriptor().FullName())
6767
}
6868

6969
env, err = c.prepareEnvironment(env, fieldDesc, constraints, forItems)

validator.go

+4
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,10 @@ func WithStandardConstraintInterceptor(interceptor StandardConstraintInterceptor
195195
// WithExtensionTypeResolver specifies a resolver to use when reparsing unknown
196196
// extension types. When dealing with dynamic file descriptor sets, passing this
197197
// option will allow extensions to be resolved using a custom resolver.
198+
//
199+
// To ignore unknown extension fields, use the [WithAllowUnknownFields] option.
200+
// Note that this may result in messages being treated as valid even though not
201+
// all constraints are being applied.
198202
func WithExtensionTypeResolver(extensionTypeResolver protoregistry.ExtensionTypeResolver) ValidatorOption {
199203
return func(c *config) {
200204
c.extensionTypeResolver = extensionTypeResolver

0 commit comments

Comments
 (0)