-
Notifications
You must be signed in to change notification settings - Fork 19
refactor: state resolution error propagation #229
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,6 +18,7 @@ import type { RoomVersion } from '@rocket.chat/federation-room'; | |
| import { resolveStateV2Plus } from '@rocket.chat/federation-room'; | ||
| import type { PduCreateEventContent } from '@rocket.chat/federation-room'; | ||
| import { checkEventAuthWithState } from '@rocket.chat/federation-room'; | ||
| import { RejectCodes } from '@rocket.chat/federation-room'; | ||
| import { singleton } from 'tsyringe'; | ||
| import { EventRepository } from '../repositories/event.repository'; | ||
| import { StateRepository, StateStore } from '../repositories/state.repository'; | ||
|
|
@@ -53,12 +54,12 @@ export class StateService { | |
| if (pdu.isState()) { | ||
| await this.persistStateEvent(pdu); | ||
| if (pdu.rejected) { | ||
| throw new Error(pdu.rejectedReason); | ||
| throw new Error(pdu.rejectReason); | ||
| } | ||
| } else { | ||
| await this.persistTimelineEvent(pdu); | ||
| if (pdu.rejected) { | ||
| throw new Error(pdu.rejectedReason); | ||
| throw new Error(pdu.rejectReason); | ||
| } | ||
| } | ||
| } | ||
|
|
@@ -506,7 +507,7 @@ export class StateService { | |
| if (!hasConflict) { | ||
| await checkEventAuthWithState(event, state, this._getStore(roomVersion)); | ||
| if (event.rejected) { | ||
| throw new Error(event.rejectedReason); | ||
| throw new Error(event.rejectReason); | ||
| } | ||
|
|
||
| // save the state mapping | ||
|
|
@@ -750,7 +751,7 @@ export class StateService { | |
|
|
||
| // we need the auth events required to validate this event from our state | ||
| const requiredAuthEventsWeHaveSeenMap = new Map< | ||
| string, | ||
| EventID, | ||
| PersistentEventBase | ||
| >(); | ||
| for (const auth of event.getAuthEventStateKeys()) { | ||
|
|
@@ -777,24 +778,27 @@ export class StateService { | |
| if (requiredAuthEventsWeHaveSeenMap.size !== authEventsReferencedMap.size) { | ||
| // incorrect length may mean either redacted event still referenced or event in state that wasn't referenced, both cases, reject the event | ||
| event.reject( | ||
| RejectCodes.AuthError, | ||
| `Auth events referenced in message do not match, expected ${requiredAuthEventsWeHaveSeenMap.size} but got ${authEventsReferencedMap.size}`, | ||
| ); | ||
| throw new Error(event.rejectedReason); | ||
| throw new Error(event.rejectReason); | ||
| } | ||
|
Comment on lines
+781
to
785
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Preserve After calling |
||
|
|
||
| for (const [eventId] of requiredAuthEventsWeHaveSeenMap) { | ||
| if (!authEventsReferencedMap.has(eventId)) { | ||
| event.reject( | ||
| RejectCodes.AuthError, | ||
| `wrong auth event in message, expected ${eventId} but not found in event`, | ||
| eventId, | ||
| ); | ||
| throw new Error(event.rejectedReason); | ||
| throw new Error(event.rejectReason); | ||
| } | ||
|
Comment on lines
787
to
795
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Propagate full rejection context Same as above: we reject the event with 🤖 Prompt for AI Agents |
||
| } | ||
|
|
||
| // now we validate against auth rules | ||
| await checkEventAuthWithState(event, room, store); | ||
| if (event.rejected) { | ||
| throw new Error(event.rejectedReason); | ||
| throw new Error(event.rejectReason); | ||
| } | ||
|
Comment on lines
798
to
802
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unhandled
🤖 Prompt for AI Agents |
||
|
|
||
| // TODO: save event still but with mark | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Return a structured HTTP error
Same issue on the remote join path: a plain
Errorbecomes a 500 and leaks an"undefined"message when the join was legitimately rejected. Emit anHttpExceptionwith a safe fallback instead.📝 Committable suggestion
🤖 Prompt for AI Agents