@@ -66,10 +66,10 @@ func (c *conn) Address() string {
6666func (c * conn ) Ping (ctx context.Context ) error {
6767 cc , err := c .realConn (ctx )
6868 if err != nil {
69- return xerrors . WithStackTrace (err )
69+ return c . wrapError (err )
7070 }
7171 if ! isAvailable (cc ) {
72- return xerrors . WithStackTrace (errUnavailableConnection )
72+ return c . wrapError (errUnavailableConnection )
7373 }
7474 return nil
7575}
@@ -115,7 +115,7 @@ func (c *conn) park(ctx context.Context) (err error) {
115115 err = c .close ()
116116
117117 if err != nil {
118- return xerrors . WithStackTrace (err )
118+ return c . wrapError (err )
119119 }
120120
121121 return nil
@@ -169,7 +169,7 @@ func (c *conn) GetState() (s State) {
169169
170170func (c * conn ) realConn (ctx context.Context ) (cc * grpc.ClientConn , err error ) {
171171 if c .isClosed () {
172- return nil , xerrors . WithStackTrace (errClosedConnection )
172+ return nil , c . wrapError (errClosedConnection )
173173 }
174174
175175 c .mtx .Lock ()
@@ -213,7 +213,7 @@ func (c *conn) realConn(ctx context.Context) (cc *grpc.ClientConn, err error) {
213213 xerrors .WithAddress (address ),
214214 )
215215
216- return nil , xerrors . WithStackTrace (
216+ return nil , c . wrapError (
217217 xerrors .Retryable (err ,
218218 xerrors .WithName ("realConn" ),
219219 ),
@@ -250,7 +250,7 @@ func (c *conn) close() (err error) {
250250 err = c .cc .Close ()
251251 c .cc = nil
252252 c .setState (Offline )
253- return xerrors . WithStackTrace (err )
253+ return c . wrapError (err )
254254}
255255
256256func (c * conn ) isClosed () bool {
@@ -286,7 +286,7 @@ func (c *conn) Close(ctx context.Context) (err error) {
286286 onClose (c )
287287 }
288288
289- return xerrors . WithStackTrace (err )
289+ return c . wrapError (err )
290290}
291291
292292func (c * conn ) Invoke (
@@ -320,7 +320,7 @@ func (c *conn) Invoke(
320320
321321 cc , err = c .realConn (ctx )
322322 if err != nil {
323- return xerrors . WithStackTrace (err )
323+ return c . wrapError (err )
324324 }
325325
326326 c .touchLastUsage ()
@@ -339,9 +339,9 @@ func (c *conn) Invoke(
339339 xerrors .WithAddress (c .Address ()),
340340 )
341341 if sentMark .canRetry () {
342- return xerrors . WithStackTrace (xerrors .Retryable (err , xerrors .WithName ("Invoke" )))
342+ return c . wrapError (xerrors .Retryable (err , xerrors .WithName ("Invoke" )))
343343 }
344- return xerrors . WithStackTrace (err )
344+ return c . wrapError (err )
345345 }
346346
347347 return err
@@ -355,10 +355,10 @@ func (c *conn) Invoke(
355355 if useWrapping {
356356 switch {
357357 case ! o .GetOperation ().GetReady ():
358- return xerrors . WithStackTrace (errOperationNotReady )
358+ return c . wrapError (errOperationNotReady )
359359
360360 case o .GetOperation ().GetStatus () != Ydb .StatusIds_SUCCESS :
361- return xerrors . WithStackTrace (
361+ return c . wrapError (
362362 xerrors .Operation (
363363 xerrors .FromOperation (o .GetOperation ()),
364364 xerrors .WithNodeAddress (c .Address ()),
@@ -406,7 +406,7 @@ func (c *conn) NewStream(
406406
407407 cc , err = c .realConn (ctx )
408408 if err != nil {
409- return nil , xerrors . WithStackTrace (err )
409+ return nil , c . wrapError (err )
410410 }
411411
412412 c .touchLastUsage ()
@@ -425,9 +425,9 @@ func (c *conn) NewStream(
425425 xerrors .WithAddress (c .Address ()),
426426 )
427427 if sentMark .canRetry () {
428- return s , xerrors . WithStackTrace (xerrors .Retryable (err , xerrors .WithName ("NewStream" )))
428+ return s , c . wrapError (xerrors .Retryable (err , xerrors .WithName ("NewStream" )))
429429 }
430- return s , xerrors . WithStackTrace (err )
430+ return s , c . wrapError (err )
431431 }
432432
433433 return s , err
@@ -446,6 +446,14 @@ func (c *conn) NewStream(
446446 }, nil
447447}
448448
449+ func (c * conn ) wrapError (err error ) error {
450+ if err == nil {
451+ return nil
452+ }
453+ nodeErr := newNodeError (c .endpoint .NodeID (), c .endpoint .Address (), err )
454+ return xerrors .WithStackTrace (nodeErr , xerrors .WithSkipDepth (1 ))
455+ }
456+
449457type option func (c * conn )
450458
451459func withOnClose (onClose func (* conn )) option {
0 commit comments