Adding upstream version 0.28.1.
Signed-off-by: Daniel Baumann <daniel@debian.org>
This commit is contained in:
parent
88f1d47ab6
commit
e28c88ef14
933 changed files with 194711 additions and 0 deletions
40
core/validators/validators.go
Normal file
40
core/validators/validators.go
Normal file
|
@ -0,0 +1,40 @@
|
|||
// Package validators implements some common custom PocketBase validators.
|
||||
package validators
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"maps"
|
||||
|
||||
validation "github.com/go-ozzo/ozzo-validation/v4"
|
||||
)
|
||||
|
||||
var ErrUnsupportedValueType = validation.NewError("validation_unsupported_value_type", "Invalid or unsupported value type.")
|
||||
|
||||
// JoinValidationErrors attempts to join the provided [validation.Errors] arguments.
|
||||
//
|
||||
// If only one of the arguments is [validation.Errors], it returns the first non-empty [validation.Errors].
|
||||
//
|
||||
// If both arguments are not [validation.Errors] then it returns a combined [errors.Join] error.
|
||||
func JoinValidationErrors(errA, errB error) error {
|
||||
vErrA, okA := errA.(validation.Errors)
|
||||
vErrB, okB := errB.(validation.Errors)
|
||||
|
||||
// merge
|
||||
if okA && okB {
|
||||
result := maps.Clone(vErrA)
|
||||
maps.Copy(result, vErrB)
|
||||
if len(result) > 0 {
|
||||
return result
|
||||
}
|
||||
}
|
||||
|
||||
if okA && len(vErrA) > 0 {
|
||||
return vErrA
|
||||
}
|
||||
|
||||
if okB && len(vErrB) > 0 {
|
||||
return vErrB
|
||||
}
|
||||
|
||||
return errors.Join(errA, errB)
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue