Skip to content

Implement MSC4387: M_SAFETY error#5107

Merged
Half-Shot merged 11 commits intodevelopfrom
hs/safety-error-code
Jan 6, 2026
Merged

Implement MSC4387: M_SAFETY error#5107
Half-Shot merged 11 commits intodevelopfrom
hs/safety-error-code

Conversation

@Half-Shot
Copy link
Contributor

@Half-Shot Half-Shot commented Dec 11, 2025

Implementation of MSC4387.

await expect(
Promise.all([client.sendTextMessage("!foo:bar", "a body", "txn1"), httpBackend.flush("/txn1", 1)]),
).rejects.toThrow("MatrixError: [500] Unknown message");
).rejects.toThrow("MatrixError: [500] Ruh roh");
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm surprised this wasn't caught before, but seems to me this has always been a bug.

* @returns Promise which resolves: to an ISendEventResponse object
* @returns Rejects: with an error response.
* @throws May throw a `MatrixSafetyError` if content is deemed unsafe.
* @see MatrixSafetyError
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewer, you may be wondering "Why has Half-Shot written a bunch of @ see MatrixSafetyError statements randomly across the file".

The intention here is to match the MSC's list of endpoints that may emit this error. I felt it was sensible to alert client developers that these endpoints may confer a specific error type if the user is trying to search or send harmful content, as oppose to usual failures.

I'm on the fence about overall usefulness, and could be persuaded they are overkill. However, it's done now so I'm going to leave unless noises are made.

@dbkr
Copy link
Member

dbkr commented Jan 5, 2026

...still being worked on

The MSC or this PR (ie. should this be a draft?)

@Half-Shot
Copy link
Contributor Author

...still being worked on

The MSC or this PR (ie. should this be a draft?)

Let me check with @turt2live on whether he is happy about the stability of the MSC for this to land.

@Half-Shot
Copy link
Contributor Author

Half-Shot commented Jan 5, 2026

...still being worked on

The MSC or this PR (ie. should this be a draft?)

@turt2live says it's "probably fine" for this to be merged :)

@turt2live
Copy link
Member

can confirm - the MSC is a bit in flux, but the changes here are stable enough. Worst case is the exact endpoints which get this treatment changes.

@Half-Shot Half-Shot added this pull request to the merge queue Jan 6, 2026
Merged via the queue into develop with commit 93f4f40 Jan 6, 2026
36 checks passed
@Half-Shot Half-Shot deleted the hs/safety-error-code branch January 6, 2026 13:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants