Skip to content

Commit

Permalink
style: format code with Gofumpt and Prettier
Browse files Browse the repository at this point in the history
This commit fixes the style issues introduced in 75cb403 according to the output
from Gofumpt and Prettier.

Details: #2639
Signed-off-by: kpango <[email protected]>
  • Loading branch information
deepsource-autofix[bot] authored and kpango committed Sep 26, 2024
1 parent 75cb403 commit a25afff
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
6 changes: 3 additions & 3 deletions internal/net/grpc/errdetails/errdetails.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ const (
ValdResourceOwner = "vdaas.org vald team <[email protected]>"
ValdGRPCResourceTypePrefix = "github.com/vdaas/vald/apis/grpc/v1"

typePrefix = "type.googleapis.com/google.rpc."
typePrefix = "type.googleapis.com/google.rpc."
typePrefixV1 = "type.googleapis.com/rpc.v1."
)

Expand Down Expand Up @@ -84,7 +84,7 @@ func (d *Detail) MarshalJSON() (body []byte, err error) {
if d == nil {
return nil, nil
}
switch strings.TrimPrefix(strings.TrimPrefix(d.TypeURL, typePrefix), typePrefixV1){
switch strings.TrimPrefix(strings.TrimPrefix(d.TypeURL, typePrefix), typePrefixV1) {
case DebugInfoMessageName:
m, ok := d.Message.(*DebugInfo)
if ok {
Expand Down Expand Up @@ -314,7 +314,7 @@ func AnyToErrorDetail(a *types.Any) proto.Message {
return nil
}
var err error
switch strings.TrimPrefix(strings.TrimPrefix(a.GetTypeUrl(), typePrefix), typePrefixV1){
switch strings.TrimPrefix(strings.TrimPrefix(a.GetTypeUrl(), typePrefix), typePrefixV1) {
case DebugInfoMessageName:
var m DebugInfo
err = types.UnmarshalAny(a, &m)
Expand Down
20 changes: 18 additions & 2 deletions internal/net/grpc/status/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,7 @@ func withDetails(st *Status, err error, details ...any) *Status {
}
}
}
m.Detail = removeDuplicatesFromTSVLine(m.GetDetail())
msgs = append(msgs, m)
case errdetails.ErrorInfoMessageName:
m := new(errdetails.ErrorInfo)
Expand Down Expand Up @@ -470,6 +471,8 @@ func withDetails(st *Status, err error, details ...any) *Status {
}
}
}
m.Reason = removeDuplicatesFromTSVLine(m.GetReason())
m.Domain = removeDuplicatesFromTSVLine(m.GetDomain())
msgs = append(msgs, m)
case errdetails.BadRequestMessageName:
m := new(errdetails.BadRequest)
Expand Down Expand Up @@ -678,8 +681,8 @@ func withDetails(st *Status, err error, details ...any) *Status {
visited[r.String()] = true
if m.GetResourceType() == "" {
m.ResourceType = r.GetResourceType()
} else if m.GetResourceType() != r.GetResourceType() && !strings.Contains(m.GetResourceType(), r.GetResourceType()) {
m.ResourceType += "\t" + r.GetResourceType()
} else if m.GetResourceType() != r.GetResourceType() && len(m.GetResourceType()) < len(r.GetResourceType()) {
m.ResourceType += r.GetResourceType()
}
if m.GetResourceName() == "" {
m.ResourceName = r.GetResourceName()
Expand Down Expand Up @@ -776,6 +779,19 @@ func appendM[K comparable](maps ...map[K]string) (result map[K]string) {
return result
}

func removeDuplicatesFromTSVLine(line string) string {
fields := strings.Split(line, "\t")
uniqueFields := make(map[string]bool)
result := make([]string, 0, len(fields))
for _, field := range fields {
if !uniqueFields[field] {
uniqueFields[field] = true
result = append(result, field)
}
}
return strings.Join(result, "\t")
}

func Log(code codes.Code, err error) {
if err != nil {
switch code {
Expand Down

0 comments on commit a25afff

Please sign in to comment.