From 64277e9bc5cd6d74b6edafa93e68b061f24ca9b1 Mon Sep 17 00:00:00 2001 From: "Kai A. Hiller" <V02460@gmail.com> Date: Tue, 6 Aug 2019 06:46:17 -0400 Subject: [PATCH] Adapt bridge error names to new matrix-appservice-bridge Signed-off-by: Kai A. Hiller <V02460@gmail.com> --- src/discordas.ts | 14 ++++++++------ src/matrixeventprocessor.ts | 17 ++++++++--------- test/test_matrixeventprocessor.ts | 6 +++--- 3 files changed, 19 insertions(+), 18 deletions(-) diff --git a/src/discordas.ts b/src/discordas.ts index f97e870..a470dff 100644 --- a/src/discordas.ts +++ b/src/discordas.ts @@ -20,11 +20,9 @@ import { BridgeContext, Cli, ClientFactory, - EventNotHandledError, - EventUnknownError, Request, - default_message, thirdPartyLookup, + unstable, } from "matrix-appservice-bridge"; import * as yaml from "js-yaml"; import * as fs from "fs"; @@ -158,6 +156,7 @@ async function run(port: number, fileConfig: DiscordBridgeConfig) { dontJoin: true, // handled manually }, }, + networkName: "Discord", // To avoid out of order message sending. queue: { perRequest: true, @@ -237,7 +236,7 @@ function logOnEventError(err: Error): void { const errTypes = []; // const warn = [EventInternalError, EventTooOldError, NotReadyError, …]; const infoTypes = []; - const verboseTypes = [EventUnknownError]; + const verboseTypes = [unstable.EventUnknownError]; switch (true) { case instanceofsome(err, errTypes): log.error(err); @@ -256,7 +255,7 @@ function recordRequestOutcome(request: Request): void { .then(() => MetricPeg.get.requestOutcome(eventId, false, "success"), ) - .catch(EventNotHandledError, (e) => + .catch(unstable.EventNotHandledError, (e) => MetricPeg.get.requestOutcome(eventId, false, "dropped"), ) .catch((e) => @@ -289,7 +288,10 @@ class NotReadyError extends Error { public name: string; constructor(...params) { - default_message(params, "The bridge was not ready when the message was sent"); + unstable.defaultMessage( + params, + "The bridge was not ready when the message was sent", + ); super(...params); this.name = "NotReadyError"; } diff --git a/src/matrixeventprocessor.ts b/src/matrixeventprocessor.ts index e286cc1..fcaa650 100644 --- a/src/matrixeventprocessor.ts +++ b/src/matrixeventprocessor.ts @@ -24,12 +24,9 @@ import * as mime from "mime"; import { Bridge, BridgeContext, - EventInternalError, - EventNotHandledError, - EventTooOldError, - EventUnknownError, MatrixUser, Request, + unstable, } from "matrix-appservice-bridge"; import { Client as MatrixClient } from "matrix-js-sdk"; import { IMatrixEvent, IMatrixEventContent, IMatrixMessage } from "./matrixtypes"; @@ -86,12 +83,14 @@ export class MatrixEventProcessor { * * @param request Request object containing the event for which this callback is called. * @param context The current context of the bridge. - * @throws {EventNotHandledError} When the event can finally not be handled. + * @throws {unstable.EventNotHandledError} When the event can finally not be handled. */ public async OnEvent(request: Request, context: BridgeContext): Promise<void> { const event = request.getData() as IMatrixEvent; if (event.unsigned.age > AGE_LIMIT) { - throw new EventTooOldError(`Skipping event due to age ${event.unsigned.age} > ${AGE_LIMIT}`); + throw new unstable.EventTooOldError( + `Skipping event due to age ${event.unsigned.age} > ${AGE_LIMIT}`, + ); } if ( event.type === "m.room.member" && @@ -153,12 +152,12 @@ export class MatrixEventProcessor { await this.HandleEncryptionWarning(event.room_id); return; } catch (err) { - throw wrap(err, EventNotHandledError, `Failed to handle encrypted room, ${err}`); + throw wrap(err, unstable.EventNotHandledError, `Failed to handle encrypted room, ${err}`); } } else { - throw new EventUnknownError("Got non m.room.message event"); + throw new unstable.EventUnknownError("Got non m.room.message event"); } - throw new EventUnknownError(); // Shouldn't be reachable + throw new unstable.EventUnknownError(); // Shouldn't be reachable } public async HandleEncryptionWarning(roomId: string): Promise<void> { diff --git a/test/test_matrixeventprocessor.ts b/test/test_matrixeventprocessor.ts index 149351a..8ac20bd 100644 --- a/test/test_matrixeventprocessor.ts +++ b/test/test_matrixeventprocessor.ts @@ -17,7 +17,7 @@ limitations under the License. import * as Chai from "chai"; import * as Discord from "discord.js"; import * as Proxyquire from "proxyquire"; -import { EventTooOldError, EventUnknownError} from "matrix-appservice-bridge"; +import { unstable } from "matrix-appservice-bridge"; import { PresenceHandler } from "../src/presencehandler"; import { DiscordBot } from "../src/bot"; @@ -818,7 +818,7 @@ This is the reply`, try { await processor.OnEvent(buildRequest({unsigned: {age: AGE}}), null); } catch (e) { err = e; } - expect(err).to.be.an.instanceof(EventTooOldError); + expect(err).to.be.an.instanceof(unstable.EventTooOldError); }); it("should reject un-processable events", async () => { const AGE = 900000; // 15 * 60 * 1000 @@ -834,7 +834,7 @@ This is the reply`, null, ); } catch (e) { err = e; } - expect(err).to.be.an.instanceof(EventUnknownError); + expect(err).to.be.an.instanceof(unstable.EventUnknownError); }); it("should handle own invites", async () => { const processor = createMatrixEventProcessor(); -- GitLab