Repository navigation
feat: log warning for Gen 1-only operations - #1063
veronika-alraheem wants to merge 1 commit into
Conversation
|
|
||
| class UnsupportedOperationError(ValueError): | ||
| """Raised when an operation is unavailable for Gen 2 Cloudant plans.""" | ||
| code = 'CLOUDANT_SDK_UNSUPPORTED_OPERATION' |
There was a problem hiding this comment.
I don't think ValueError is the correct class, from the docs:
Raised when an operation or function receives an argument that has the right type but an inappropriate value
TypeError on the other hand says:
This exception may be raised by user code to indicate that an attempted operation on an object is not supported, and is not meant to be.
That seems like a better fit for what we're doing here. As such I also think we could raise a TypeError directly, I don't think we need a specific sub-class (similar to how Java uses a built-in UnsupportedOperationException).
Noting for completeness that another option, NotImplementedError, specifically says:
It should not be used to indicate that an operator or method is not meant to be supported at all
| def test_error_has_code_and_is_a_value_error(self): | ||
| self._set_env('true') | ||
| with self.assertRaises(UnsupportedOperationError) as cm: | ||
| self.service.get_cors_information() | ||
| self.assertEqual('CLOUDANT_SDK_UNSUPPORTED_OPERATION', cm.exception.code) | ||
| self.assertIsInstance(cm.exception, ValueError) |
There was a problem hiding this comment.
Obsolete if we raise a built-in TypeError as there will be no code. The other tests already assert the exception type in assertRaisesRegex anyway.
a05e86d to
64d517c
Compare
PR summary
Emit a log warning for operations only available for Gen 1.
Fixes i1318
PR Checklist
Please make sure that your PR fulfills the following requirements:
Angular Commit Message Guidelines.
PR Type
What is the current behavior?
Calls to Gen 1-only operations execute without any user-facing warning that they are unavailable for Gen 2.
What is the new behavior?
gen1_only_rulecovers the Gen 1-only operations. Whenprepare_requestfinds it for an operation, it logs a warning and still sends the request.CLOUDANT_SDK_GEN1_ERRORS=trueraises anUnsupportedOperationError.Does this PR introduce a breaking change?
Other information