better message formatting
Some checks failed
ci/woodpecker/push/billing_fees Pipeline was successful
ci/woodpecker/push/bff Pipeline was successful
ci/woodpecker/push/db Pipeline was successful
ci/woodpecker/push/chain_gateway Pipeline was successful
ci/woodpecker/push/fx_ingestor Pipeline was successful
ci/woodpecker/push/fx_oracle Pipeline was successful
ci/woodpecker/push/frontend Pipeline was successful
ci/woodpecker/push/payments_orchestrator Pipeline was successful
ci/woodpecker/push/bump_version Pipeline failed
ci/woodpecker/push/nats Pipeline was successful
ci/woodpecker/push/ledger Pipeline was successful
ci/woodpecker/push/notification Pipeline was successful

This commit is contained in:
Stephan D
2025-11-19 13:54:25 +01:00
parent 62956b06ca
commit 717dafc673
26 changed files with 202 additions and 56 deletions

View File

@@ -3,6 +3,7 @@ package merrors
import (
"errors"
"fmt"
"strings"
"go.mongodb.org/mongo-driver/bson/primitive"
)
@@ -27,8 +28,8 @@ func Internal(msg string) error {
var ErrInvalidArg = errors.New("invalidArgError")
func InvalidArgument(msg string) error {
return fmt.Errorf("%w: %s", ErrInvalidArg, msg)
func InvalidArgument(msg string, argumentNames ...string) error {
return fmt.Errorf("%w: %s", ErrInvalidArg, invalidArgumentMessage(msg, argumentNames...))
}
var ErrDataConflict = errors.New("DataConflict")
@@ -64,8 +65,8 @@ func NoMessagingTopic(topic string) error {
return fmt.Errorf("%w: messaging topic '%s' not found", ErrNoMessagingTopic, topic)
}
func InvalidArgumentWrap(err error, msg string) error {
return wrapError(ErrInvalidArg, msg, err)
func InvalidArgumentWrap(err error, msg string, argumentNames ...string) error {
return wrapError(ErrInvalidArg, invalidArgumentMessage(msg, argumentNames...), err)
}
func InternalWrap(err error, msg string) error {
@@ -79,3 +80,23 @@ func wrapError(base error, msg string, err error) error {
}
return errors.Join(baseErr, err)
}
func invalidArgumentMessage(msg string, argumentNames ...string) string {
names := make([]string, 0, len(argumentNames))
for _, name := range argumentNames {
name = strings.TrimSpace(name)
if name == "" {
continue
}
names = append(names, fmt.Sprintf("%q", name))
}
if len(names) == 0 {
return msg
}
prefix := "broken argument"
if len(names) > 1 {
prefix = "broken arguments"
}
return fmt.Sprintf("%s %s: %s", prefix, strings.Join(names, ", "), msg)
}