aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNeil Alexander <neilalexander@users.noreply.github.com>2020-10-15 14:14:17 +0100
committerNeil Alexander <neilalexander@users.noreply.github.com>2020-10-15 14:14:17 +0100
commite154c45b5188846f8f8abf56d6e7979fc7bb98b7 (patch)
tree04c0d348c6a29cc4ccbaa94e6660a099918b9b0e
parent49abe359e6a2b0c3f214190b73404c5cf9a0e051 (diff)
Better logging around db.StoreEvent
-rw-r--r--roomserver/storage/shared/storage.go21
1 files changed, 15 insertions, 6 deletions
diff --git a/roomserver/storage/shared/storage.go b/roomserver/storage/shared/storage.go
index e96eab71..f2be8b3c 100644
--- a/roomserver/storage/shared/storage.go
+++ b/roomserver/storage/shared/storage.go
@@ -458,7 +458,7 @@ func (d *Database) StoreEvent(
eventNID, stateNID, err = d.EventsTable.SelectEvent(ctx, txn, event.EventID())
}
if err != nil {
- return err
+ return fmt.Errorf("d.EventsTable.SelectEvent: %w", err)
}
}
@@ -467,6 +467,9 @@ func (d *Database) StoreEvent(
}
if !isRejected { // ignore rejected redaction events
redactionEvent, redactedEventID, err = d.handleRedactions(ctx, txn, eventNID, event)
+ if err != nil {
+ return fmt.Errorf("d.handleRedactions: %w", err)
+ }
}
return nil
})
@@ -627,6 +630,7 @@ func extractRoomVersionFromCreateEvent(event gomatrixserverlib.Event) (
// to cross-reference with other tables when loading.
//
// Returns the redaction event and the event ID of the redacted event if this call resulted in a redaction.
+// nolint:gocyclo
func (d *Database) handleRedactions(
ctx context.Context, txn *sql.Tx, eventNID types.EventNID, event gomatrixserverlib.Event,
) (*gomatrixserverlib.Event, string, error) {
@@ -644,13 +648,13 @@ func (d *Database) handleRedactions(
RedactsEventID: event.Redacts(),
})
if err != nil {
- return nil, "", err
+ return nil, "", fmt.Errorf("d.RedactionsTable.InsertRedaction: %w", err)
}
}
redactionEvent, redactedEvent, validated, err := d.loadRedactionPair(ctx, txn, eventNID, event)
if err != nil {
- return nil, "", err
+ return nil, "", fmt.Errorf("d.loadRedactionPair: %w", err)
}
if validated || redactedEvent == nil || redactionEvent == nil {
// we've seen this redaction before or there is nothing to redact
@@ -664,7 +668,7 @@ func (d *Database) handleRedactions(
// mark the event as redacted
err = redactedEvent.SetUnsignedField("redacted_because", redactionEvent)
if err != nil {
- return nil, "", err
+ return nil, "", fmt.Errorf("redactedEvent.SetUnsignedField: %w", err)
}
if redactionsArePermanent {
redactedEvent.Event = redactedEvent.Redact()
@@ -672,10 +676,15 @@ func (d *Database) handleRedactions(
// overwrite the eventJSON table
err = d.EventJSONTable.InsertEventJSON(ctx, txn, redactedEvent.EventNID, redactedEvent.JSON())
if err != nil {
- return nil, "", err
+ return nil, "", fmt.Errorf("d.EventJSONTable.InsertEventJSON: %w", err)
+ }
+
+ err = d.RedactionsTable.MarkRedactionValidated(ctx, txn, redactionEvent.EventID(), true)
+ if err != nil {
+ err = fmt.Errorf("d.RedactionsTable.MarkRedactionValidated: %w", err)
}
- return &redactionEvent.Event, redactedEvent.EventID(), d.RedactionsTable.MarkRedactionValidated(ctx, txn, redactionEvent.EventID(), true)
+ return &redactionEvent.Event, redactedEvent.EventID(), err
}
// loadRedactionPair returns both the redaction event and the redacted event, else nil.