Skip to content

Commit b150fe8

Browse files
authored
fix: Correctly store last event id (#99)
* fix: Correctly store last event id * Revert LastEventID return type When LastEventID() returns EventID (string) instead of *EventID, user code gets simpler because it doesn't need a nil-check.
1 parent c558d82 commit b150fe8

File tree

2 files changed

+34
-3
lines changed

2 files changed

+34
-3
lines changed

hub.go

+21-3
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,13 @@ func (hub *Hub) CaptureEvent(event *Event) *EventID {
210210
if client == nil || scope == nil {
211211
return nil
212212
}
213-
return client.CaptureEvent(event, nil, scope)
213+
eventID := client.CaptureEvent(event, nil, scope)
214+
if eventID != nil {
215+
hub.lastEventID = *eventID
216+
} else {
217+
hub.lastEventID = ""
218+
}
219+
return eventID
214220
}
215221

216222
// CaptureMessage calls the method of a same name on currently bound `Client` instance
@@ -221,7 +227,13 @@ func (hub *Hub) CaptureMessage(message string) *EventID {
221227
if client == nil || scope == nil {
222228
return nil
223229
}
224-
return client.CaptureMessage(message, nil, scope)
230+
eventID := client.CaptureMessage(message, nil, scope)
231+
if eventID != nil {
232+
hub.lastEventID = *eventID
233+
} else {
234+
hub.lastEventID = ""
235+
}
236+
return eventID
225237
}
226238

227239
// CaptureException calls the method of a same name on currently bound `Client` instance
@@ -232,7 +244,13 @@ func (hub *Hub) CaptureException(exception error) *EventID {
232244
if client == nil || scope == nil {
233245
return nil
234246
}
235-
return client.CaptureException(exception, &EventHint{OriginalException: exception}, scope)
247+
eventID := client.CaptureException(exception, &EventHint{OriginalException: exception}, scope)
248+
if eventID != nil {
249+
hub.lastEventID = *eventID
250+
} else {
251+
hub.lastEventID = ""
252+
}
253+
return eventID
236254
}
237255

238256
// AddBreadcrumb records a new breadcrumb.

hub_test.go

+13
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,19 @@ func TestLastEventID(t *testing.T) {
177177
assertEqual(t, uuid, hub.LastEventID())
178178
}
179179

180+
func TestLastEventIDUpdatesAfterCaptures(t *testing.T) {
181+
hub, _, _ := setupHubTest()
182+
183+
messageID := hub.CaptureMessage("wat")
184+
assertEqual(t, *messageID, hub.LastEventID())
185+
186+
errorID := hub.CaptureException(fmt.Errorf("wat"))
187+
assertEqual(t, *errorID, hub.LastEventID())
188+
189+
eventID := hub.CaptureEvent(&Event{Message: "wat"})
190+
assertEqual(t, *eventID, hub.LastEventID())
191+
}
192+
180193
func TestLayerAccessingEmptyStack(t *testing.T) {
181194
hub := &Hub{}
182195
if hub.stackTop() != nil {

0 commit comments

Comments
 (0)