-
Notifications
You must be signed in to change notification settings - Fork 40
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
Enumerate errors for peek_with_timeout #456
base: master
Are you sure you want to change the base?
Conversation
Pull Request Test Coverage Report for Build 12614809624Details
💛 - Coveralls |
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.
concept ACK 7f27c9d, though it seems like a complete this would really entail defining an Error enum containing both RedisResult's RedisError
and Elapsed rather than the Ok value being a RedisResult.
Perhaps add one more commit that does that.
A docstring describing the behavior of peek_v1 (or any function) is absolutely appropriate and encouraged.
Ah makes sense, ill update this hopefully tomorrow |
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.
Nice, this is what I was looking for.
I think it would be more appropriate for the DbPoolError to be defined in db.rs, (potentially named db::Error) since it's not an error on the whole lib, but rather the db module specifically. Additionally, I would expect a payjoin-directory/src/error.rs to host HandlerError defined as lib.rs too, and since there's only one error type it may not be worth the overhead of new files and imports for the time being.
I also see an opportunity to reduce duplicate code in lib.rs since the pattern is repeated:
fn handle_peek(
result: Result<Vec<u8>, DbPoolError>,
timeout_response: Response<BoxBody<Bytes, hyper::Error>>,
) -> Result<Response<BoxBody<Bytes, hyper::Error>>, HandlerError> {
match result {
Ok(buffered_req) => Ok(Response::new(full(buffered_req))),
Err(e) => match e {
DbPoolError::Redis(re) => Err(HandlerError::BadRequest(re.into())),
DbPoolError::Timeout(_) => Ok(timeout_response),
},
}
}
May you follow up with the module cleanup (putting the new error in db.rs)? The deduplication is optional, since duplicate code is already contained in this repo and keeping it around would not be a regression. But i'd like to see it :)
Thanks for the persistent contributions 🫡
Err(e) => Err(HandlerError::BadRequest(e.into())), | ||
Ok(buffered_req) => Ok(Response::new(full(buffered_req))), | ||
Err(e) => match e { | ||
DbPoolError::Redis(_) => Err(HandlerError::BadRequest(e.into())), |
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.
IF we want to return the Redis error to the client (big IF, @nothingmuch what do you think) I think we can return Redis(e) => Err(HandlerError::BadRequest(e.into()) rather than the top level error, since that's the only returned variant. Then Err(_) => match e
is appropriate at the higher level.
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 the concern here that Redis will be replaced in the near future (#419), or just generally that the client shouldn't have to worry about the underlying implementation?
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.
exposing internals of the server
- isn't generally actionable by most callers
- should just be error logged instead and
- exposes details about the server state that potentially could be used for an attack. though I'm not sure I can think of one off the top of my head, my idea of best practice is to reveal only that necessary and actionable serverstate for the client to operate and keep everything else private.
@@ -0,0 +1,25 @@ | |||
#[derive(Debug)] | |||
pub enum DbPoolError { |
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 think this needs to be pub(crate)
since we don't plan to expose it in the public API.
Feedback makes sense, I'll move the error and add the dedupe. I'll wait until the Redis error propagation discussion is resolved before pushing all of the updates here at once |
I returned the same values for the new
Error
case that were previously returned for aNone
in thepeek_default
andpeek_v1
usages to maintain the same behavior. Maybe it'd be useful to update them to say something about a timeout?Fixes #396