-
Notifications
You must be signed in to change notification settings - Fork 252
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
feat(WidgetDriver): Pass Matrix API errors to the widget #4241
base: main
Are you sure you want to change the base?
Conversation
1b1a0fb
to
0dd249f
Compare
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #4241 +/- ##
==========================================
+ Coverage 84.87% 84.94% +0.06%
==========================================
Files 274 274
Lines 29719 29735 +16
==========================================
+ Hits 25225 25257 +32
+ Misses 4494 4478 -16 ☔ View full report in Codecov by Sentry. |
0dd249f
to
cccf7a0
Compare
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.
Makes sense! But we need many more comments for this, please; let's try to add them as we touch these files.
@@ -76,7 +76,7 @@ where | |||
|
|||
pub(crate) fn then( | |||
self, | |||
response_handler: impl FnOnce(Result<T, String>, &mut WidgetMachine) -> Vec<Action> | |||
response_handler: impl FnOnce(Result<T, crate::Error>, &mut WidgetMachine) -> Vec<Action> |
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.
Since you're around, can you add a doc comment to this function please?
} | ||
} | ||
|
||
#[derive(Serialize)] | ||
struct FromWidgetError { | ||
message: String, | ||
matrix_api_error: Option<FromWidgetMatrixErrorBody>, |
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.
This crate is barely documented, which makes it super hard to understand how it works. Let's change that; of course I wouldn't have you change all of it at once, so let's try to do it incrementally. The doc comments don't have to be long; a single short descriptive line is sufficient to give us a rough idea of why/how it's used.
Please add a doc comment to:
- every single struct/enum you're adding fields to (here,
FromWidgetError
) - every field/variant from those structs/enums (here,
message
above) - every new struct/enum/field/variant
http_headers: HashMap<String, String>, | ||
url: String, | ||
response: Value, | ||
} |
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.
nit: always add a newline after a block closing
} | |
} | |
struct FromWidgetMatrixErrorBody { | ||
http_status: u32, | ||
// TODO: figure out the which type to use here. | ||
http_headers: HashMap<String, String>, | ||
url: String, | ||
response: Value, |
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.
I want doc comments everywhere here too please :)
@@ -38,7 +38,7 @@ pub(crate) enum IncomingMessage { | |||
request_id: Uuid, | |||
|
|||
/// The result of the request: response data or error message. | |||
response: Result<MatrixDriverResponse, String>, | |||
response: Result<MatrixDriverResponse, crate::Error>, |
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.
The doc comment above needs an update^^
@@ -118,7 +116,7 @@ impl MatrixDriver { | |||
state_key: Option<String>, | |||
content: Box<RawJsonValue>, | |||
delayed_event_parameters: Option<delayed_events::DelayParameters>, | |||
) -> Result<SendEventResponse> { | |||
) -> Result<SendEventResponse, Error> { |
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.
ditto here
@@ -54,17 +52,17 @@ impl MatrixDriver { | |||
} | |||
|
|||
/// Requests an OpenID token for the current user. | |||
pub(crate) async fn get_open_id(&self) -> HttpResult<OpenIdResponse> { | |||
pub(crate) async fn get_open_id(&self) -> Result<OpenIdResponse, Error> { |
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.
no need to specify the error type here neither
@@ -167,9 +165,9 @@ impl MatrixDriver { | |||
&self, | |||
delay_id: String, | |||
action: UpdateAction, | |||
) -> HttpResult<delayed_events::update_delayed_event::unstable::Response> { | |||
) -> Result<delayed_events::update_delayed_event::unstable::Response, Error> { |
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.
nit: no need to specify the Error
here too
@@ -195,7 +195,7 @@ impl<T: CapabilitiesProvider> ProcessingContext<T> { | |||
self.to_widget_tx.send(msg).await.map_err(|_| ())?; | |||
} | |||
Action::MatrixDriverRequest { request_id, data } => { | |||
let response = match data { | |||
let response: Result<MatrixDriverResponse, Error> = match data { |
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.
Is this explicit type declaration needed?
.await; | ||
|
||
Mock::given(method("PUT")) | ||
.and(path_regex(r"^/_matrix/client/v3/rooms/.*/send/m.room.message/.*$")) |
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.
We have a mock in the MatrixMockServer
called .mock_room_send()
, can you use that instead?
Currently the WidgetDriver just returns unspecified error strings to the widget that can be used to display an issue description to the user. It is not helpful to run code like a retry or other error mitigation logic.
Here it is proposed to add standardized errors for issues that every widget driver implementation can run into (all matrix cs api errors): matrix-org/matrix-spec-proposals#2762 (comment)
This PR forwards the errors that occur during the widget processing to the widget in the correct format.
NOTE:
It does not include request Url and http Headers. See also: matrix-org/matrix-spec-proposals#2762 (comment)
Signed-off-by: