Wrap createConnectionForState/ensureGrant in a try/catch (#680)

* Fix thrown exception when the state is not granted

* changelog

* make it an error

* Typing
This commit is contained in:
Will Hunt 2023-03-24 14:39:19 +00:00 committed by GitHub
parent 6c4bbc7150
commit 037674115a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 15 deletions

1
changelog.d/680.bugfix Normal file
View File

@ -0,0 +1 @@
Fix a missing grant for a connection sometimes causing a crash.

View File

@ -173,7 +173,7 @@ export class ConnectionManager extends EventEmitter {
* @param rollbackBadState
* @returns
*/
public async createConnectionForState(roomId: string, state: StateEvent<any>, rollbackBadState: boolean) {
public async createConnectionForState(roomId: string, state: StateEvent<any>, rollbackBadState: boolean): Promise<IConnection|undefined> {
// Empty object == redacted
if (state.content.disabled === true || Object.keys(state.content).length === 0) {
log.debug(`${roomId} has disabled state for ${state.type}`);
@ -195,6 +195,7 @@ export class ConnectionManager extends EventEmitter {
return;
}
try {
const connection = await connectionType.createConnectionForState(roomId, state, {
as: this.as,
intent: botUser.intent,
@ -205,10 +206,13 @@ export class ConnectionManager extends EventEmitter {
storage: this.storage,
github: this.github,
});
// Finally, ensure the connection is allowed by us.
await connection.ensureGrant?.(state.sender);
return connection;
} catch (ex) {
log.error(`Not creating connection for state ${roomId}/${state.type}`, ex);
return;
}
}
/**