Bootstrap copied BFF and local accounts with public Sendico contracts (#34)
This commit is contained in:
1 parent
67dc5b5b1e
commit
7062672a87
556 files changed
+42291
-777
No files matched your search
@@ -0,0 +1,44 @@
|
||||
package merrors
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// InvalidArgumentClassified returns an invalid-argument error with a stable
|
||||
// machine reason and structured field names for transport adapters.
|
||||
func InvalidArgumentClassified(reason, msg string, argumentNames ...string) error {
|
||||
return classifiedError{
|
||||
base: ErrInvalidArg,
|
||||
msg: invalidArgumentMessage(msg, argumentNames...),
|
||||
reason: strings.TrimSpace(reason),
|
||||
argumentNames: normalizeArgumentNames(argumentNames),
|
||||
}
|
||||
}
|
||||
|
||||
func invalidArgumentMessage(msg string, argumentNames ...string) string {
|
||||
normalizedNames := normalizeArgumentNames(argumentNames)
|
||||
names := make([]string, 0, len(normalizedNames))
|
||||
for _, name := range normalizedNames {
|
||||
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)
|
||||
}
|
||||
|
||||
func normalizeArgumentNames(argumentNames []string) []string {
|
||||
names := make([]string, 0, len(argumentNames))
|
||||
for _, name := range argumentNames {
|
||||
if name = strings.TrimSpace(name); name != "" {
|
||||
names = append(names, name)
|
||||
}
|
||||
}
|
||||
return names
|
||||
}
|
||||
Reference in new issue
Block a user