Skip to content

Commit

Permalink
added TestErrorBrief
Browse files Browse the repository at this point in the history
  • Loading branch information
asmyasnikov committed Oct 23, 2023
1 parent 461b0fe commit ae69b15
Show file tree
Hide file tree
Showing 4 changed files with 384 additions and 34 deletions.
6 changes: 6 additions & 0 deletions internal/xerrors/transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,5 +182,11 @@ func TransportError(err error) Error {
if errors.As(err, &t) {
return t
}
if s, ok := grpcStatus.FromError(err); ok {
return &transportError{
status: s,
err: err,
}
}
return nil
}
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 ae69b15

Please sign in to comment.