@@ -64,7 +64,7 @@ func (o *defaultDialer) defaultConn(ctx context.Context) (*URLOpener, error) {
64
64
}
65
65
conn , err := amqp .Dial (serverURL )
66
66
if err != nil {
67
- return nil , fmt .Errorf ("failed to dial RABBIT_SERVER_URL %q: %v " , serverURL , err )
67
+ return nil , fmt .Errorf ("failed to dial RABBIT_SERVER_URL %q: %w " , serverURL , err )
68
68
}
69
69
o .conn = conn
70
70
o .opener = & URLOpener {Connection : conn }
@@ -74,15 +74,15 @@ func (o *defaultDialer) defaultConn(ctx context.Context) (*URLOpener, error) {
74
74
func (o * defaultDialer ) OpenTopicURL (ctx context.Context , u * url.URL ) (* pubsub.Topic , error ) {
75
75
opener , err := o .defaultConn (ctx )
76
76
if err != nil {
77
- return nil , fmt .Errorf ("open topic %v: failed to open default connection: %v " , u , err )
77
+ return nil , fmt .Errorf ("open topic %v: failed to open default connection: %w " , u , err )
78
78
}
79
79
return opener .OpenTopicURL (ctx , u )
80
80
}
81
81
82
82
func (o * defaultDialer ) OpenSubscriptionURL (ctx context.Context , u * url.URL ) (* pubsub.Subscription , error ) {
83
83
opener , err := o .defaultConn (ctx )
84
84
if err != nil {
85
- return nil , fmt .Errorf ("open subscription %v: failed to open default connection: %v " , u , err )
85
+ return nil , fmt .Errorf ("open subscription %v: failed to open default connection: %w " , u , err )
86
86
}
87
87
return opener .OpenSubscriptionURL (ctx , u )
88
88
}
@@ -335,7 +335,8 @@ func (t *topic) SendBatch(ctx context.Context, ms []*driver.Message) error {
335
335
}
336
336
// If there is only one error, return it rather than a MultiError. That
337
337
// will work better with ErrorCode and ErrorAs.
338
- if merr , ok := err .(MultiError ); ok && len (merr ) == 1 {
338
+ var merr MultiError
339
+ if errors .As (err , & merr ) && len (merr ) == 1 {
339
340
return merr [0 ]
340
341
}
341
342
return err
@@ -478,8 +479,8 @@ var errorCodes = map[int]gcerrors.ErrorCode{
478
479
}
479
480
480
481
func errorCode (err error ) gcerrors.ErrorCode {
481
- aerr , ok := err .( * amqp.Error )
482
- if ! ok {
482
+ var aerr * amqp.Error
483
+ if ! errors . As ( err , & aerr ) {
483
484
return gcerrors .Unknown
484
485
}
485
486
if ec , ok := errorCodes [aerr .Code ]; ok {
@@ -489,8 +490,8 @@ func errorCode(err error) gcerrors.ErrorCode {
489
490
}
490
491
491
492
func isRetryable (err error ) bool {
492
- aerr , ok := err .( * amqp.Error )
493
- if ! ok {
493
+ var aerr * amqp.Error
494
+ if ! errors . As ( err , & aerr ) {
494
495
return false
495
496
}
496
497
// amqp.Error has a Recover field which sounds like it should mean "retryable".
@@ -540,18 +541,22 @@ func (*topic) ErrorAs(err error, i interface{}) bool {
540
541
}
541
542
542
543
func errorAs (err error , i interface {}) bool {
543
- switch e := err .( type ) {
544
- case * amqp. Error :
544
+ var aerr * amqp. Error
545
+ if errors . As ( err , & aerr ) {
545
546
if p , ok := i .(* * amqp.Error ); ok {
546
- * p = e
547
+ * p = aerr
547
548
return true
548
549
}
549
- case MultiError :
550
+ }
551
+
552
+ var merr MultiError
553
+ if errors .As (err , & merr ) {
550
554
if p , ok := i .(* MultiError ); ok {
551
- * p = e
555
+ * p = merr
552
556
return true
553
557
}
554
558
}
559
+
555
560
return false
556
561
}
557
562
@@ -691,7 +696,8 @@ func (s *subscription) ReceiveBatch(ctx context.Context, maxMessages int) ([]*dr
691
696
if err := closeErr (s .closec ); err != nil {
692
697
// PreconditionFailed can happen if we send an Ack or Nack for a
693
698
// message that has already been acked/nacked. Ignore those errors.
694
- if aerr , ok := err .(* amqp.Error ); ok && aerr .Code == amqp .PreconditionFailed {
699
+ var aerr * amqp.Error
700
+ if errors .As (err , & aerr ) && aerr .Code == amqp .PreconditionFailed {
695
701
return nil , nil
696
702
}
697
703
return nil , err
0 commit comments