errors

package
v0.8.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 30, 2024 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FieldPath added in v0.8.0

FieldPath returns a single-element buf.validate.FieldPath corresponding to the provided FieldDescriptor, or nil if the provided FieldDescriptor is nil.

func FieldPathElement added in v0.8.0

func FieldPathElement(field protoreflect.FieldDescriptor) *validate.FieldPathElement

FieldPathElement returns a buf.validate.FieldPathElement that corresponds to a provided FieldDescriptor. If the provided FieldDescriptor is nil, nil is returned.

func FieldPathString added in v0.8.0

func FieldPathString(path []*validate.FieldPathElement) string

FieldPathString takes a FieldPath and encodes it to a string-based dotted field path.

func FinalizePaths added in v0.8.0

func FinalizePaths(err error)

FinalizePaths reverses all field paths in the error and populates the deprecated string-based field path.

func MarkForKey added in v0.2.1

func MarkForKey(err error)

MarkForKey marks the provided error as being for a map key, by setting the `for_key` flag on each violation within the validation error.

func Merge

func Merge(dst, src error, failFast bool) (ok bool, err error)

Merge is a utility to resolve and combine errors resulting from evaluation. If ok is false, execution of validation should stop (either due to failFast or the result is not a ValidationError).

func UpdatePaths added in v0.8.0

func UpdatePaths(err error, fieldSuffix *validate.FieldPathElement, rulePrefix []*validate.FieldPathElement)

UpdatePaths modifies the field and rule paths of an error, appending an element to the end of each field path (if provided) and prepending a list of elements to the beginning of each rule path (if provided.)

Note that this function is ordinarily used to append field paths in reverse order, as the stack bubbles up through the evaluators. Then, at the end, the path is reversed. Rule paths are generally static, so this optimization isn't applied for rule paths.

Types

type CompilationError

type CompilationError struct {
	// contains filtered or unexported fields
}

A CompilationError is returned if a CEL expression cannot be compiled & type-checked or if invalid standard constraints are applied.

func NewCompilationError

func NewCompilationError(cause error) *CompilationError

NewCompilationError creates a new CompilationError with the provided cause.

func NewCompilationErrorf

func NewCompilationErrorf(format string, args ...any) *CompilationError

NewCompilationErrorf creates a new CompilationError, constructing a causal error from the provided format and args.

func (*CompilationError) Error

func (err *CompilationError) Error() string

func (*CompilationError) Unwrap

func (err *CompilationError) Unwrap() error

type RuntimeError

type RuntimeError struct {
	// contains filtered or unexported fields
}

A RuntimeError is returned if a valid CEL expression evaluation is terminated. The two built-in reasons are 'no_matching_overload' when a CEL function has no overload for the types of the arguments or 'no_such_field' when a map or message does not contain the desired field.

func NewRuntimeError

func NewRuntimeError(cause error) *RuntimeError

NewRuntimeError creates a new RuntimeError with the provided cause.

func NewRuntimeErrorf

func NewRuntimeErrorf(format string, args ...any) *RuntimeError

NewRuntimeErrorf creates a new RuntimeError, constructing a causal error from the provided format and args.

func (*RuntimeError) Error

func (err *RuntimeError) Error() string

func (*RuntimeError) Unwrap

func (err *RuntimeError) Unwrap() error

type ValidationError

type ValidationError struct {
	Violations []*Violation
}

A ValidationError is returned if one or more constraint violations were detected.

func (*ValidationError) Error

func (err *ValidationError) Error() string

func (*ValidationError) ToProto

func (err *ValidationError) ToProto() *validate.Violations

ToProto converts this error into its proto.Message form.

type Violation added in v0.8.0

type Violation struct {
	// Proto contains the violation's proto.Message form.
	Proto *validate.Violation

	// FieldValue contains the value of the specific field that failed
	// validation. If there was no value, this will contain an invalid value.
	FieldValue protoreflect.Value

	// FieldDescriptor contains the field descriptor corresponding to the
	// field that failed validation.
	FieldDescriptor protoreflect.FieldDescriptor

	// RuleValue contains the value of the rule that specified the failed
	// constraint. Not all constraints have a value; only standard and
	// predefined constraints have rule values. In violations caused by other
	// kinds of constraints, like custom contraints, this will contain an
	// invalid value.
	RuleValue protoreflect.Value

	// RuleDescriptor contains the field descriptor corresponding to the
	// rule that failed validation.
	RuleDescriptor protoreflect.FieldDescriptor
}

Violation represents a single instance where a validation rule was not met. It provides information about the field that caused the violation, the specific unfulfilled constraint, and a human-readable error message.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL