Skip to content

Conversation

@coryan
Copy link
Contributor

@coryan coryan commented Mar 13, 2018

This fixes #119. Instead of raising a plain std::runtime_error
exception with the information in the what() string the
library now raises bigtble::GRpcError with the relevant
grpc::Status fields (error code, error message, and error details).
The class is derived from std::runtime_error because that is
the exception that one should use to, well, represent run-time
errors, which these are.

coryan and others added 3 commits March 12, 2018 23:22
Instead of raising a plain std::runtime_error use a more detailed
exception that derives from it.  This fixes googleapis#119.
@googlebot googlebot added the cla: yes This human has signed the Contributor License Agreement. label Mar 13, 2018
Because the previous reformat was wrong, grrr.
Copy link

@deepankarsharma deepankarsharma left a comment

Choose a reason for hiding this comment

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

Added questions.


namespace bigtable {
inline namespace BIGTABLE_CLIENT_NS {
constexpr char const* kKnownCodes[] = {

Choose a reason for hiding this comment

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

Does grpc not have a way to convert error codes to their textual representation?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

bigtable::GRpcError ex(msg, status);
std::cerr << "Aborting because exceptions are disabled: " << ex.what()
<< std::endl;
std::abort();

Choose a reason for hiding this comment

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

  1. Could you clarify the error handling strategy here from a users point of view?
  2. In the exceptions case will the exception be raised all the way to the user, or will we catch it and do the appropriate thing in the bigtable client codebase?
  3. What do we expect the user to do in the no exceptions case?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The exceptions are raised all the way to the user. If the user compiled without exceptions the error "handling" is we abort. If the user is called "Google" there is an internal API to catch (most) errors without exceptions. This pending PR has more context:

https://github.com/GoogleCloudPlatform/google-cloud-cpp/pull/98/files

grpc::Status const& status);

private:
grpc::StatusCode error_code_;

Choose a reason for hiding this comment

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

In case this exception will reach users drop usage of grpc::StatusCode and change name away from GRpcError.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Why? The error represents a run-time problem, reported by gRPC, that stops the library from completing its work. Is not like we want (or could if we wanted to) hide the fact that gRPC is the underlying RPC mechanism.

@coryan
Copy link
Contributor Author

coryan commented Mar 14, 2018

Let me know if those answers make sense. Happy to discuss in person if the github reviews do not provide enough bandwidth.

@coryan
Copy link
Contributor Author

coryan commented Mar 14, 2018

Per our offline discussion, I updated the documentation and created a bug for that idea around making the call to std::abort() configurable. PTAL.

Copy link

@deepankarsharma deepankarsharma left a comment

Choose a reason for hiding this comment

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

Looks good.

@coryan coryan merged commit 86c4006 into googleapis:master Mar 14, 2018
@coryan coryan deleted the wrap-grpc-status-with-exception branch March 14, 2018 20:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla: yes This human has signed the Contributor License Agreement.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Create std::exception that wraps a grpc::Status

3 participants