mirror of
https://github.com/matrix-org/dendrite.git
synced 2026-01-12 00:23:10 -06:00
Create a reusable error for invalid room info
This commit is contained in:
parent
f8c0dd78dc
commit
eabda06b59
|
|
@ -221,7 +221,7 @@ func loadAuthEvents(
|
|||
}
|
||||
|
||||
if roomInfo == nil {
|
||||
err = fmt.Errorf("cannot get events without room info")
|
||||
err = types.ErrorInvalidRoomInfo
|
||||
return
|
||||
}
|
||||
if result.events, err = db.Events(ctx, roomInfo.RoomVersion, eventNIDs); err != nil {
|
||||
|
|
|
|||
|
|
@ -184,7 +184,7 @@ func GetMembershipsAtState(
|
|||
|
||||
// Get all of the events in this state
|
||||
if roomInfo == nil {
|
||||
return nil, fmt.Errorf("cannot get events without room info")
|
||||
return nil, types.ErrorInvalidRoomInfo
|
||||
}
|
||||
stateEvents, err := db.Events(ctx, roomInfo.RoomVersion, eventNIDs)
|
||||
if err != nil {
|
||||
|
|
@ -239,7 +239,7 @@ func LoadEvents(
|
|||
ctx context.Context, db storage.RoomDatabase, roomInfo *types.RoomInfo, eventNIDs []types.EventNID,
|
||||
) ([]gomatrixserverlib.PDU, error) {
|
||||
if roomInfo == nil {
|
||||
return nil, fmt.Errorf("cannot get events without room info")
|
||||
return nil, types.ErrorInvalidRoomInfo
|
||||
}
|
||||
stateEvents, err := db.Events(ctx, roomInfo.RoomVersion, eventNIDs)
|
||||
if err != nil {
|
||||
|
|
|
|||
|
|
@ -806,7 +806,7 @@ func (r *Inputer) kickGuests(ctx context.Context, event gomatrixserverlib.PDU, r
|
|||
}
|
||||
|
||||
if roomInfo == nil {
|
||||
return fmt.Errorf("cannot get events without room info")
|
||||
return types.ErrorInvalidRoomInfo
|
||||
}
|
||||
memberEvents, err := r.DB.Events(ctx, roomInfo.RoomVersion, membershipNIDs)
|
||||
if err != nil {
|
||||
|
|
|
|||
|
|
@ -564,7 +564,7 @@ func joinEventsFromHistoryVisibility(
|
|||
|
||||
// Get all of the events in this state
|
||||
if roomInfo == nil {
|
||||
return nil, gomatrixserverlib.HistoryVisibilityJoined, fmt.Errorf("cannot get events without room info")
|
||||
return nil, gomatrixserverlib.HistoryVisibilityJoined, types.ErrorInvalidRoomInfo
|
||||
}
|
||||
stateEvents, err := db.Events(ctx, roomInfo.RoomVersion, eventNIDs)
|
||||
if err != nil {
|
||||
|
|
|
|||
|
|
@ -270,7 +270,7 @@ func buildInviteStrippedState(
|
|||
stateNIDs = append(stateNIDs, stateNID.EventNID)
|
||||
}
|
||||
if info == nil {
|
||||
return nil, fmt.Errorf("cannot get events without room info")
|
||||
return nil, types.ErrorInvalidRoomInfo
|
||||
}
|
||||
stateEvents, err := db.Events(ctx, info.RoomVersion, stateNIDs)
|
||||
if err != nil {
|
||||
|
|
|
|||
|
|
@ -86,7 +86,7 @@ func (p *StateResolution) Resolve(ctx context.Context, eventID string) (*gomatri
|
|||
}
|
||||
|
||||
if p.roomInfo == nil {
|
||||
return nil, fmt.Errorf("cannot get events without room info")
|
||||
return nil, types.ErrorInvalidRoomInfo
|
||||
}
|
||||
events, err := p.db.Events(ctx, p.roomInfo.RoomVersion, []types.EventNID{plNID})
|
||||
if err != nil {
|
||||
|
|
@ -1139,7 +1139,7 @@ func (v *StateResolution) loadStateEvents(
|
|||
}
|
||||
|
||||
if v.roomInfo == nil {
|
||||
return nil, nil, fmt.Errorf("cannot get events without room info")
|
||||
return nil, nil, types.ErrorInvalidRoomInfo
|
||||
}
|
||||
events, err := v.db.Events(ctx, v.roomInfo.RoomVersion, eventNIDs)
|
||||
if err != nil {
|
||||
|
|
|
|||
|
|
@ -118,7 +118,7 @@ func (u *RoomUpdater) StorePreviousEvents(eventNID types.EventNID, previousEvent
|
|||
|
||||
func (u *RoomUpdater) Events(ctx context.Context, _ gomatrixserverlib.RoomVersion, eventNIDs []types.EventNID) ([]types.Event, error) {
|
||||
if u.roomInfo == nil {
|
||||
return nil, fmt.Errorf("cannot get events without room info")
|
||||
return nil, types.ErrorInvalidRoomInfo
|
||||
}
|
||||
return u.d.events(ctx, u.txn, u.roomInfo.RoomVersion, eventNIDs)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -393,7 +393,7 @@ func (d *EventDatabase) eventsFromIDs(ctx context.Context, txn *sql.Tx, roomInfo
|
|||
}
|
||||
|
||||
if roomInfo == nil {
|
||||
return nil, fmt.Errorf("cannot get events without room info")
|
||||
return nil, types.ErrorInvalidRoomInfo
|
||||
}
|
||||
return d.events(ctx, txn, roomInfo.RoomVersion, nids)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@ package types
|
|||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"sort"
|
||||
"strings"
|
||||
"sync"
|
||||
|
|
@ -328,3 +329,5 @@ func (r *RoomInfo) CopyFrom(r2 *RoomInfo) {
|
|||
r.stateSnapshotNID = r2.stateSnapshotNID
|
||||
r.isStub = r2.isStub
|
||||
}
|
||||
|
||||
var ErrorInvalidRoomInfo = fmt.Errorf("room info is invalid")
|
||||
|
|
|
|||
Loading…
Reference in a new issue