mirror of
https://github.com/optim-enterprises-bv/vault.git
synced 2025-10-30 10:12:35 +00:00
VAULT-24798: audit - improve error messages (#26312)
* audit: remove 'op' from error messages and do some clean up * Allow early error checking to be concerned with vault/Core vs. audit
This commit is contained in:
@@ -4,7 +4,6 @@
|
||||
package event
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
"strconv"
|
||||
@@ -59,18 +58,24 @@ func getOpts(opt ...Option) (options, error) {
|
||||
return opts, nil
|
||||
}
|
||||
|
||||
// ValidateOptions can be used to validate options before they are required.
|
||||
func ValidateOptions(opt ...Option) error {
|
||||
_, err := getOpts(opt...)
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
// NewID is a bit of a modified NewID has been done to stop a circular
|
||||
// dependency with the errors package that is caused by importing
|
||||
// boundary/internal/db
|
||||
func NewID(prefix string) (string, error) {
|
||||
const op = "event.NewID"
|
||||
if prefix == "" {
|
||||
return "", fmt.Errorf("%s: missing prefix: %w", op, ErrInvalidParameter)
|
||||
return "", fmt.Errorf("missing prefix: %w", ErrInvalidParameter)
|
||||
}
|
||||
|
||||
id, err := uuid.GenerateUUID()
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("%s: unable to generate ID: %w", op, err)
|
||||
return "", fmt.Errorf("unable to generate ID: %w", err)
|
||||
}
|
||||
|
||||
return fmt.Sprintf("%s_%s", prefix, id), nil
|
||||
@@ -84,7 +89,7 @@ func WithID(id string) Option {
|
||||
id := strings.TrimSpace(id)
|
||||
switch {
|
||||
case id == "":
|
||||
err = errors.New("id cannot be empty")
|
||||
err = fmt.Errorf("id cannot be empty: %w", ErrInvalidParameter)
|
||||
default:
|
||||
o.withID = id
|
||||
}
|
||||
@@ -100,7 +105,7 @@ func WithNow(now time.Time) Option {
|
||||
|
||||
switch {
|
||||
case now.IsZero():
|
||||
err = errors.New("cannot specify 'now' to be the zero time instant")
|
||||
err = fmt.Errorf("cannot specify 'now' to be the zero time instant: %w", ErrInvalidParameter)
|
||||
default:
|
||||
o.withNow = now
|
||||
}
|
||||
@@ -159,7 +164,7 @@ func WithMaxDuration(duration string) Option {
|
||||
|
||||
parsed, err := parseutil.ParseDurationSecond(duration)
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to parse max duration: %w", err)
|
||||
return fmt.Errorf("unable to parse max duration: %w: %w", ErrInvalidParameter, err)
|
||||
}
|
||||
|
||||
o.withMaxDuration = parsed
|
||||
@@ -187,7 +192,7 @@ func WithFileMode(mode string) Option {
|
||||
|
||||
switch {
|
||||
case err != nil:
|
||||
return fmt.Errorf("unable to parse file mode: %w", err)
|
||||
return fmt.Errorf("unable to parse file mode: %w: %w", ErrInvalidParameter, err)
|
||||
default:
|
||||
m := os.FileMode(raw)
|
||||
o.withFileMode = &m
|
||||
|
||||
Reference in New Issue
Block a user