-
Notifications
You must be signed in to change notification settings - Fork 5
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
Replace all unwraps #147
Replace all unwraps #147
Conversation
ef8d06f
to
726f66a
Compare
src/data/attribute.rs
Outdated
result.push((current_prefix, serde_json::to_string(&v).unwrap())); | ||
result.push(( | ||
current_prefix, | ||
serde_json::to_string(&v).expect("failed to serialize json 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.
Would this contain any information about v
? If not, maybe .inspect
or otherwise use the error to log?
I'd maybe even go as far as dropping that mapping on the floor, log at error! Or explicitly add a null
value or... rather than having the whole process crash?
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.
In what cases would the serialization fail?
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.
Right, given the above, it can only be String
, Bool
, null
or some Number... so I guess it shouldn't ever fail indeed... for as long as that invariant remains true tho...
src/service.rs
Outdated
@@ -57,7 +57,8 @@ impl GrpcService { | |||
) -> Result<GrpcResult, StatusCode> { | |||
let failure_mode = operation.get_failure_mode(); | |||
if let Some(res_body_bytes) = | |||
hostcalls::get_buffer(BufferType::GrpcReceiveBuffer, 0, resp_size).unwrap() | |||
hostcalls::get_buffer(BufferType::GrpcReceiveBuffer, 0, resp_size) | |||
.expect("failed to get_buffer on GrpcReceiveBuffer") |
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.
Should this leverage FailureMode
?
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.
Yep good point, this and below should be handled
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've handled this by wrapping the Some
with an Ok
... however I think this is the wrong way to be doing this. This one function is handling multiple different error cases internally and either sending an error or resuming the request based on failure mode, eventually returning an Err(StatusCode::InternalServerError)
to the caller - I feel like this could/should be handled by the caller instead but needs some more serious thought in #127
c2fe283
to
d245019
Compare
4e8e92e
to
d5c5404
Compare
@@ -64,7 +64,7 @@ impl AuthService { | |||
let mut request = AttributeContext_Request::default(); | |||
let mut http = AttributeContext_HttpRequest::default(); | |||
let headers: HashMap<String, String> = hostcalls::get_map(MapType::HttpRequestHeaders) | |||
.unwrap() | |||
.expect("failed to retrieve HttpRequestHeaders from host") |
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.
Let's leave this for now (and the other 2 calls below, as well as the one in rate_limit.rs
), but I think this should eventually become some kind of FailureMode
dependent behavior...
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.
100% agreed again here
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 expect adds some info, but still causes a panic...which is what we're looking to avoid, no?
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.
maybe unwrap_or() and provide some sane default (an empty map?)?
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 primary problem is this should perform an action based on the FailureMode
defined for the service - if this service is set to Deny
then we don't want to populate the request with a default value and let it through. This is a much larger refactor though than can be solved in this PR
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.
provide some sane default (an empty map?)?
there is no "sane default" in this case, as it will just propagate the error to the next inline... i.e. in this case probably the CEL expression is going to fail. This error here tho, would mean something went wrong with envoy.
As @adam-cattermole rightly pointed out, this would need to fallback to some user configured behavior (analogous to e.g. Limitador being unreachable). So we need to get rid of this one when we figured out that part of the issue (see this "issue" for more context)
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.
But let's wait on what others in the team think wrt the lint
I use it, and recommend it, but it can be quite a bit of work ... I proposed this quite a while back, before we (if we were going to support more the library model) stabilized the API, as I expected a lot of return values to have to change to Result<> |
Signed-off-by: Adam Cattermole <[email protected]>
Signed-off-by: Adam Cattermole <[email protected]>
d5c5404
to
b3d4307
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.
👍🏼
This is definitively true for Limitador... here, things a slightly different tho. But yes this is more work, yet useful work... if we don't just replace |
unwrap_used
- this is in a separate commit so we can drop it before we merge