Skip to content

feat: log warning for Gen 1-only operations - #1063

Open
veronika-alraheem wants to merge 1 commit into
mainfrom
1318-gen1-warnings
Open

veronika-alraheem wants to merge 1 commit into
mainfrom
1318-gen1-warnings

Conversation

@veronika-alraheem

Copy link
Copy Markdown
Contributor

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:

  • The commit message follows the
    Angular Commit Message Guidelines.
  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been added / updated (for bug fixes / features)

PR Type

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • New tests
  • Build/CI related changes
  • Documentation content changes
  • Other (please describe)

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?

  • A new gen1_only_rule covers the Gen 1-only operations. When prepare_request finds it for an operation, it logs a warning and still sends the request.
  • Setting CLOUDANT_SDK_GEN1_ERRORS=true raises an UnsupportedOperationError.

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

Comment thread ibmcloudant/cloudant_base_service.py Outdated

class UnsupportedOperationError(ValueError):
"""Raised when an operation is unavailable for Gen 2 Cloudant plans."""
code = 'CLOUDANT_SDK_UNSUPPORTED_OPERATION'

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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

Comment on lines +104 to +109
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)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants