Co-authored-by: hashicorp-copywrite[bot] <110428419+hashicorp-copywrite[bot]@users.noreply.github.com>
27 lines
625 B
Go
27 lines
625 B
Go
// Copyright IBM Corp. 2025, 2026
|
|
// SPDX-License-Identifier: MPL-2.0
|
|
|
|
package errors
|
|
|
|
import (
|
|
"fmt"
|
|
"sort"
|
|
"strings"
|
|
|
|
"google.golang.org/grpc/codes"
|
|
"google.golang.org/grpc/status"
|
|
)
|
|
|
|
// InvalidArgumentError returns an grpc invalid argument status error.
|
|
func InvalidArgumentError(msg string, f map[string]string) error {
|
|
var fieldMsgs []string
|
|
for field, val := range f {
|
|
fieldMsgs = append(fieldMsgs, fmt.Sprintf("%s: %s", field, val))
|
|
}
|
|
if len(fieldMsgs) > 0 {
|
|
sort.Strings(fieldMsgs)
|
|
msg = fmt.Sprintf("%s: [%s]", msg, strings.Join(fieldMsgs, ", "))
|
|
}
|
|
return status.Error(codes.InvalidArgument, msg)
|
|
}
|