Skip to content
This repository has been archived by the owner on Sep 10, 2024. It is now read-only.

Improve errors when MAS contacts the Synapse homeserver #2794

Merged
merged 8 commits into from
Jun 7, 2024

Conversation

reivilibre
Copy link
Contributor

An example of a failed registration now looks like:

Screenshot_20240523_172645

Before the only detail this gave you was the headline message repeated a few times.

The logs now say

2024-05-23T16:26:32.863728Z ERROR http.server.request{otel.kind="server" otel.name="POST /register" network.protocol.name="http" network.protocol.version="1.1" http.request.method="POST" url.path="/register" url.scheme="http" http.route="/register" user_agent.original="Mozilla/5.0 (X11; Linux x86_64; rv:125.0) Gecko/20100101 Firefox/125.0"}:handlers.views.register.post: mas_handlers::views::register: error=Internal error: Failed to query localpart availability from Synapse (Failed to query localpart availability from Synapse

Caused by:
    request failed with status 401 Unauthorized: M_UNKNOWN_TOKEN: Invalid access token passed.)

Should be commit-by-commit review friendly

@reivilibre reivilibre requested a review from sandhose May 23, 2024 16:29
Copy link

cloudflare-workers-and-pages bot commented May 23, 2024

Deploying matrix-authentication-service-docs with  Cloudflare Pages  Cloudflare Pages

Latest commit: 6351613
Status: ✅  Deploy successful!
Preview URL: https://6f4d6e84.matrix-authentication-service-docs.pages.dev
Branch Preview URL: https://rei-homeserver-error-improve.matrix-authentication-service-docs.pages.dev

View logs

@reivilibre reivilibre marked this pull request as ready for review May 23, 2024 16:33
@reivilibre reivilibre force-pushed the rei/homeserver_error_improvements branch from fe137dd to 0f94a93 Compare May 24, 2024 11:47
crates/http/src/layers/catch_http_codes.rs Outdated Show resolved Hide resolved
crates/http/src/ext.rs Outdated Show resolved Hide resolved
crates/http/src/ext.rs Outdated Show resolved Hide resolved
crates/http/src/ext.rs Outdated Show resolved Hide resolved
templates/pages/error.html Show resolved Hide resolved
Comment on lines 37 to 43
fn description(&self) -> &str {
if let Some(matrix_error) = &self.matrix_error {
&matrix_error.error
} else {
"Homeserver Error"
}
}
Copy link
Member

Choose a reason for hiding this comment

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

description has been deprecated for a while, it's delegated to Debug/Display now

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 think you still have to implement it? Maybe I should have just hardcoded a "don't description() me, you silly!" on it but ehh

Copy link
Member

Choose a reason for hiding this comment

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

looks like the stdlib already does that for you :)

https://doc.rust-lang.org/stable/src/core/error.rs.html#110

Copy link
Contributor Author

Choose a reason for hiding this comment

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

huh ok, weird that it added it (rust analyser?) for implementation then. Maybe it just always does that and I'm used to IntelliJ-Rust too much

crates/matrix-synapse/src/lib.rs Outdated Show resolved Hide resolved
Comment on lines 210 to 213
#[derive(Deserialize)]
struct UsernameAvailableResponse {
available: bool,
}
Copy link
Member

Choose a reason for hiding this comment

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

The other response structures are defined at the top of the file, for consitency could you move that up there?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sure. It's just a personal style I like for these single-use structs, to make them function-local, but yeah indeed there are others here so let's do that

@reivilibre reivilibre requested a review from sandhose June 3, 2024 10:55
Copy link
Member

@sandhose sandhose left a comment

Choose a reason for hiding this comment

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

woop, forgot to get back to this, sorry

If you could just remove the Error::description implementation and move the UsernameAvailableResponse struct, otherwise lgtm

Comment on lines 37 to 43
fn description(&self) -> &str {
if let Some(matrix_error) = &self.matrix_error {
&matrix_error.error
} else {
"Homeserver Error"
}
}
Copy link
Member

Choose a reason for hiding this comment

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

looks like the stdlib already does that for you :)

https://doc.rust-lang.org/stable/src/core/error.rs.html#110

Using `#[source]` is unnatural here because it makes it look like
two distinct errors (one being a cause of the other),
when in reality it is just one error, with 2 parts.

Using `Display` formatting for that leads to a more natural error.
Not strictly required, but does two things:

- documents what kind of function is expected
- provides a small extra amount of type enforcement at the call site,
  rather than later on when you find the result doesn't implement Service
Nothing major, just a quality of life improvement so you don't have to
repetitively write out what a HTTP error is
…etails' section

The extra whitespace was probably unintentional and makes the error harder to read,
particularly when it wraps onto a new line unnecessarily
@reivilibre reivilibre force-pushed the rei/homeserver_error_improvements branch from 3dcda7f to 6351613 Compare June 7, 2024 11:06
@reivilibre reivilibre enabled auto-merge (squash) June 7, 2024 11:07
@reivilibre reivilibre merged commit 49e8fe5 into main Jun 7, 2024
16 checks passed
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants