github.com/ydb-platform/ydb-go-sdk/v3@v3.57.0/metrics/error_brief.go (about) 1 package metrics 2 3 import ( 4 "context" 5 "io" 6 "net" 7 8 "github.com/ydb-platform/ydb-go-sdk/v3/internal/xerrors" 9 "github.com/ydb-platform/ydb-go-sdk/v3/internal/xstring" 10 ) 11 12 func errorBrief(err error) string { 13 if err == nil { 14 return "OK" 15 } 16 if xerrors.Is(err, io.EOF) { 17 return "io/EOF" 18 } 19 if netErr := (*net.OpError)(nil); xerrors.As(err, &netErr) { 20 buffer := xstring.Buffer() 21 defer buffer.Free() 22 buffer.WriteString("network") 23 if netErr.Op != "" { 24 buffer.WriteByte('/') 25 buffer.WriteString(netErr.Op) 26 } 27 if netErr.Addr != nil { 28 buffer.WriteByte('[') 29 buffer.WriteString(netErr.Addr.String()) 30 buffer.WriteByte(']') 31 } 32 if netErr.Err != nil { 33 buffer.WriteByte('(') 34 buffer.WriteString(errorBrief(netErr.Err)) 35 buffer.WriteByte(')') 36 } 37 38 return buffer.String() 39 } 40 if xerrors.Is(err, context.DeadlineExceeded) { 41 return "context/DeadlineExceeded" 42 } 43 if xerrors.Is(err, context.Canceled) { 44 return "context/Canceled" 45 } 46 if xerrors.IsTransportError(err) { 47 return xerrors.TransportError(err).Name() 48 } 49 if xerrors.IsOperationErrorTransactionLocksInvalidated(err) { 50 return "operation/ABORTED/TLI" 51 } 52 if xerrors.IsOperationError(err) { 53 return xerrors.OperationError(err).Name() 54 } 55 if ydbErr := xerrors.Error(nil); xerrors.As(err, &ydbErr) { 56 return ydbErr.Name() 57 } 58 59 return "unknown" 60 }