You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by GitBox <gi...@apache.org> on 2020/08/09 18:49:49 UTC

[GitHub] [pulsar] Bklyn opened a new issue #7787: [pulsar-client-cpp] Should throw `std::exception` (or a subtype), not `const char*`

Bklyn opened a new issue #7787:
URL: https://github.com/apache/pulsar/issues/7787


   **Is your enhancement request related to a problem? Please describe.**
   The Pulsar C++ client library throws `const char*` in several locations instead of `std::exception` or a derived type.
   
   **Describe the solution you'd like**
   Throw `std::exception` or some derived type instead.
   
   **Describe alternatives you've considered**
   If you're going to throw something, `std::exception` is the expected type in modern C++
   
   **Details**
   ```c++
   /lib/MessageBuilder.cc:112:        throw "sequenceId needs to be >= 0";
   ./lib/CompressionCodecSnappy.cc:59:    throw "Snappy compression not supported";
   ./lib/CompressionCodecSnappy.cc:64:    throw "Snappy compression not supported";
   ./lib/ProducerConfiguration.cc:70:        throw "maxPendingMessages needs to be greater than 0";
   ./lib/ProducerConfiguration.cc:80:        throw "maxPendingMessages needs to be greater than 0";
   ./lib/ProducerConfiguration.cc:134:        throw "batchingMaxMessages needs to be greater than 1";
   ./lib/ConsumerConfiguration.cc:96:        throw "Consumer Config Exception: Unacknowledged message timeout should be greater than 10 seconds.";
   ./lib/auth/AuthOauth2.cc:105:        throw "ExpiresIn in Oauth2TokenResult invalid value: " + expiredIn;
   ./lib/auth/AuthToken.cc:55:        throw "Failed to read environment variable " + envVarName;
   ./lib/auth/AuthToken.cc:77:        throw "Invalid configuration for token provider";
   ./lib/MessageId.cc:79:        throw "Failed to parse serialized message id";
   ./lib/CompressionCodecZstd.cc:61:SharedBuffer CompressionCodecZstd::encode(const SharedBuffer& raw) { throw "ZStd compression not supported"; }
   ./lib/CompressionCodecZstd.cc:65:    throw "ZStd compression not supported";
   ```
   Invalid arguments or bad config (i.e. `sequenceId needs to be >= 0`) should result in `std::invalid_argument`.  The `not supported` exceptions should perhaps be `runtime_error` or maybe just bare `exception`s.


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [pulsar] BewareMyPower commented on issue #7787: [pulsar-client-cpp] Should throw std::exception (or a subtype), not const char*

Posted by GitBox <gi...@apache.org>.
BewareMyPower commented on issue #7787:
URL: https://github.com/apache/pulsar/issues/7787#issuecomment-671720191


   I agree with you. Throwing a `std::invalid_argument` is a better choice. The pulsar C++ client doesn't use exceptions except for fail-fast, but throwing a `const char*` won't print any message, while throwing an exception would print the message of `what()` method.
   
   Would you like to submit a PR?


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [pulsar] sijie closed issue #7787: [pulsar-client-cpp] Should throw std::exception (or a subtype), not const char*

Posted by GitBox <gi...@apache.org>.
sijie closed issue #7787:
URL: https://github.com/apache/pulsar/issues/7787


   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [pulsar] Bklyn commented on issue #7787: [pulsar-client-cpp] Should throw std::exception (or a subtype), not const char*

Posted by GitBox <gi...@apache.org>.
Bklyn commented on issue #7787:
URL: https://github.com/apache/pulsar/issues/7787#issuecomment-671933101


   @BewareMyPower I will


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org