-
Notifications
You must be signed in to change notification settings - Fork 3
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
Add a function to call gRPC stubs and wrap errors #58
Conversation
40b0b5f
to
0da9195
Compare
Not sure what's going on with the DCO app that is not running the check 😒 |
0da9195
to
196b5be
Compare
) -> ExampleResponseWrapper: | ||
return await call_stub_method( | ||
self, | ||
lambda: self.stub.example_method( |
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 would suggest to use explicit parameter names here to avoid having ahem the reader accidentally thinking it is a parameter name 😇
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.
Haha, too much rust going on? 😛
Will do.
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.
Looking at the code I'm not so convinced now. The function is called "call stub method", isn't it pretty obvious that what you are passing is... ahem, the stub method?
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 thinks forcing to use:
call_stub_method(self, stub_method=lambda: self.stub.example_method())
Might be a bit too verbose.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
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.
Made an optional suggestion
Signed-off-by: Leandro Lucarella <luca-frequenz@llucax.com>
The name `auto_connect` could be misleading, as users might think that, for example, the client might connect automatically when a method is called when this option is `True`, but this option only controls if the client is connected when it is created. Signed-off-by: Leandro Lucarella <luca-frequenz@llucax.com>
The new function `call_stub_method()` simplifies the common error wrapping when calling stub methods, so errors are automatically converted to `ApiClientError`s. It also checks that the client is connected and raises an appropriate exception if it is not. Finally, if a transform function is provided, the response will be automatically transformed too. Signed-off-by: Leandro Lucarella <luca-frequenz@llucax.com>
Signed-off-by: Leandro Lucarella <luca-frequenz@llucax.com>
Signed-off-by: Leandro Lucarella <luca-frequenz@llucax.com>
Signed-off-by: Leandro Lucarella <luca-frequenz@llucax.com>
03b8a93
to
c65f366
Compare
Updated with @shsms suggestion. |
As @Marenz comment was also optional I'm enabling auto-merge. |
The new function
call_stub_method()
simplifies the common error wrapping when calling stub methods, so errors are automatically converted toApiClientError
s. It also checks that the client is connected and raises an appropriate exception if it is not. Finally, if a transform function is provided, the response will be automatically transformed too.This PR also adds an example to the
BaseApiClient
documentation, including using the newcall_stub_method()
function.