storj/satellite/console/validation.go
Egon Elbre 961e841bd7 all: fix error naming
errs.Class should not contain "error" in the name, since that causes a
lot of stutter in the error logs. As an example a log line could end up
looking like:

    ERROR node stats service error: satellitedbs error: node stats database error: no rows

Whereas something like:

    ERROR nodestats service: satellitedbs: nodestatsdb: no rows

Would contain all the necessary information without the stutter.

Change-Id: I7b7cb7e592ebab4bcfadc1eef11122584d2b20e0
2021-04-29 15:38:21 +03:00

54 lines
1.2 KiB
Go

// Copyright (C) 2019 Storj Labs, Inc.
// See LICENSE for copying information.
package console
import (
"github.com/zeebo/errs"
)
const (
passMinLength = 6
)
// ErrValidation validation related error class.
var ErrValidation = errs.Class("validation")
// validationError is slice of ErrValidation class errors.
type validationErrors []error
// Addf adds a new ErrValidation error to validation.
func (validation *validationErrors) Addf(format string, args ...interface{}) {
*validation = append(*validation, ErrValidation.New(format, args...))
}
// AddWrap adds new ErrValidation wrapped err.
func (validation *validationErrors) AddWrap(err error) {
*validation = append(*validation, ErrValidation.Wrap(err))
}
// Combine returns combined validation errors.
func (validation *validationErrors) Combine() error {
return errs.Combine(*validation...)
}
// ValidatePassword validates password.
func ValidatePassword(pass string) error {
var errs validationErrors
if len(pass) < passMinLength {
errs.Addf(passwordIncorrectErrMsg, passMinLength)
}
return errs.Combine()
}
// ValidateFullName validates full name.
func ValidateFullName(name string) error {
if name == "" {
return errs.New("full name can not be empty")
}
return nil
}