Skip to content

Commit

Permalink
Merge pull request #870 from ydb-platform/errors-brief-test
Browse files Browse the repository at this point in the history
added `metrics.TestErrorBrief` + allowed to create `xerrors.TransportError()` from grpc status error
  • Loading branch information
asmyasnikov authored Oct 23, 2023
2 parents 2ea6388 + 42d9fba commit e6cf18a
Show file tree
Hide file tree
Showing 3 changed files with 378 additions and 34 deletions.
34 changes: 0 additions & 34 deletions metrics/error.go

This file was deleted.

55 changes: 55 additions & 0 deletions metrics/error_brief.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package metrics

import (
"context"
"io"
"net"

"github.com/ydb-platform/ydb-go-sdk/v3/internal/allocator"
"github.com/ydb-platform/ydb-go-sdk/v3/internal/xerrors"
)

func errorBrief(err error) string {
if err == nil {
return "OK"
}
if xerrors.Is(err, io.EOF) {
return "io/EOF"
}
if netErr := (*net.OpError)(nil); xerrors.As(err, &netErr) {
buffer := allocator.Buffers.Get()
defer allocator.Buffers.Put(buffer)
buffer.WriteString("network")
if netErr.Op != "" {
buffer.WriteByte('/')
buffer.WriteString(netErr.Op)
}
if netErr.Addr != nil {
buffer.WriteByte('[')
buffer.WriteString(netErr.Addr.String())
buffer.WriteByte(']')
}
if netErr.Err != nil {
buffer.WriteByte('(')
buffer.WriteString(errorBrief(netErr.Err))
buffer.WriteByte(')')
}
return buffer.String()
}
if xerrors.Is(err, context.DeadlineExceeded) {
return "context/DeadlineExceeded"
}
if xerrors.Is(err, context.Canceled) {
return "context/Canceled"
}
if xerrors.IsTransportError(err) {
return xerrors.TransportError(err).Name()
}
if xerrors.IsOperationError(err) {
return xerrors.OperationError(err).Name()
}
if ydbErr := xerrors.Error(nil); xerrors.As(err, &ydbErr) {
return ydbErr.Name()
}
return "unknown"
}
Loading

0 comments on commit e6cf18a

Please sign in to comment.