Skip to content
This repository was archived by the owner on Aug 30, 2023. It is now read-only.

Commit 0d6ed3c

Browse files
author
Valentin Krasontovitsch
committed
Return error when waiting for packet to be sent
The client's capture method returns an error channel that according to the docs is intended to be used for checking if a packet was sent successfully whenever that is important. The `...AndWait` methods use this channel, but only to wait. They do not capture the possible error coming from that channel. The changes in this commit suggest to use the error and return it, so that a user may check whether a packet was sent successfully using the top level methods (like `CaptureMessageAndWait`), instead of having to write their own. **Breaking changes**: The signatures of the following methods are changed: ``` - [Client.]CaptureMessageAndWait - [Client.]CaptureErrorAndWait - [Client.]CapturePanicAndWait ``` Work on #84
1 parent d3909e6 commit 0d6ed3c

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

client.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ func newTransport() Transport {
318318
} else {
319319
t.Client = &http.Client{
320320
Transport: &http.Transport{
321-
Proxy: http.ProxyFromEnvironment,
321+
Proxy: http.ProxyFromEnvironment,
322322
TLSClientConfig: &tls.Config{RootCAs: rootCAs},
323323
},
324324
}
@@ -608,7 +608,7 @@ func CaptureMessage(message string, tags map[string]string, interfaces ...Interf
608608
}
609609

610610
// CaptureMessageAndWait is identical to CaptureMessage except it blocks and waits for the message to be sent.
611-
func (client *Client) CaptureMessageAndWait(message string, tags map[string]string, interfaces ...Interface) string {
611+
func (client *Client) CaptureMessageAndWait(message string, tags map[string]string, interfaces ...Interface) (error, string) {
612612
if client == nil {
613613
return ""
614614
}
@@ -619,13 +619,13 @@ func (client *Client) CaptureMessageAndWait(message string, tags map[string]stri
619619

620620
packet := NewPacket(message, append(append(interfaces, client.context.interfaces()...), &Message{message, nil})...)
621621
eventID, ch := client.Capture(packet, tags)
622-
<-ch
622+
internalError := <-ch
623623

624-
return eventID
624+
return internalError, eventID
625625
}
626626

627627
// CaptureMessageAndWait is identical to CaptureMessage except it blocks and waits for the message to be sent.
628-
func CaptureMessageAndWait(message string, tags map[string]string, interfaces ...Interface) string {
628+
func CaptureMessageAndWait(message string, tags map[string]string, interfaces ...Interface) (error, string) {
629629
return DefaultClient.CaptureMessageAndWait(message, tags, interfaces...)
630630
}
631631

@@ -655,7 +655,7 @@ func CaptureError(err error, tags map[string]string, interfaces ...Interface) st
655655
}
656656

657657
// CaptureErrorAndWait is identical to CaptureError, except it blocks and assures that the event was sent
658-
func (client *Client) CaptureErrorAndWait(err error, tags map[string]string, interfaces ...Interface) string {
658+
func (client *Client) CaptureErrorAndWait(err error, tags map[string]string, interfaces ...Interface) (error, string) {
659659
if client == nil {
660660
return ""
661661
}
@@ -666,13 +666,13 @@ func (client *Client) CaptureErrorAndWait(err error, tags map[string]string, int
666666

667667
packet := NewPacket(err.Error(), append(append(interfaces, client.context.interfaces()...), NewException(err, NewStacktrace(1, 3, client.includePaths)))...)
668668
eventID, ch := client.Capture(packet, tags)
669-
<-ch
669+
internalError := <-ch
670670

671-
return eventID
671+
return internalError, eventID
672672
}
673673

674674
// CaptureErrorAndWait is identical to CaptureError, except it blocks and assures that the event was sent
675-
func CaptureErrorAndWait(err error, tags map[string]string, interfaces ...Interface) string {
675+
func CaptureErrorAndWait(err error, tags map[string]string, interfaces ...Interface) (error, string) {
676676
return DefaultClient.CaptureErrorAndWait(err, tags, interfaces...)
677677
}
678678

@@ -716,7 +716,7 @@ func CapturePanic(f func(), tags map[string]string, interfaces ...Interface) (in
716716
}
717717

718718
// CapturePanicAndWait is identical to CaptureError, except it blocks and assures that the event was sent
719-
func (client *Client) CapturePanicAndWait(f func(), tags map[string]string, interfaces ...Interface) (err interface{}, errorID string) {
719+
func (client *Client) CapturePanicAndWait(f func(), tags map[string]string, interfaces ...Interface) (internalError error, err interface{}, errorID string) {
720720
// Note: This doesn't need to check for client, because we still want to go through the defer/recover path
721721
// Down the line, Capture will be noop'd, so while this does a _tiny_ bit of overhead constructing the
722722
// *Packet just to be thrown away, this should not be the normal case. Could be refactored to
@@ -742,15 +742,15 @@ func (client *Client) CapturePanicAndWait(f func(), tags map[string]string, inte
742742

743743
var ch chan error
744744
errorID, ch = client.Capture(packet, tags)
745-
<-ch
745+
internalError = <-ch
746746
}()
747747

748748
f()
749749
return
750750
}
751751

752752
// CapturePanicAndWait is identical to CaptureError, except it blocks and assures that the event was sent
753-
func CapturePanicAndWait(f func(), tags map[string]string, interfaces ...Interface) (interface{}, string) {
753+
func CapturePanicAndWait(f func(), tags map[string]string, interfaces ...Interface) (error, interface{}, string) {
754754
return DefaultClient.CapturePanicAndWait(f, tags, interfaces...)
755755
}
756756

0 commit comments

Comments
 (0)