Skip to content
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 GlobusSDKUsageError & replace most ValueErrors #281

Merged
merged 1 commit into from
Feb 23, 2018

Conversation

sirosen
Copy link
Member

@sirosen sirosen commented Feb 23, 2018

The GlobusSDKUsageError is just class GlobusSDKUsageError(GlobusError, ValueError): pass

It replaces many uses of ValueError to indicate that an SDK method has been misused. This acts as an additional hint to users that they haven't read docs carefully enough, and makes us more conformant to our stated policy of only raising GlobusErrors unless otherwise noted.

That latter part (being consistent with our docs) is the one I care more about.
I left ValueError in place where it "felt appropriate", so feel free to call me out on that if any of it looks wrong.

Simple example:

globus_sdk.ConfidentialAppAuthClient(
    'a', 'b', authorizer=globus_sdk.AccessTokenAuthorizer('foo'))

now raises GlobusSDKUsageError, not ValueError, for passing authorizer to a confidential client.

Resolves #139

@sirosen sirosen added enhancement New feature or improvement error handling labels Feb 23, 2018
Copy link
Contributor

@corpulentcoffee corpulentcoffee left a comment

Choose a reason for hiding this comment

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

I'm fine with this idea. Obviously it should be mentioned in the release notes in case anyone has anything like try: . . . except GlobusError: . . . except ValueError: . . . in client code.

How about the ValueError that can be raised from BaseClient's __init__()?

@@ -30,7 +31,8 @@

"GlobusResponse", "GlobusHTTPResponse",

"GlobusError", "GlobusAPIError", "TransferAPIError", "SearchAPIError",
"GlobusError", "GlobusSDKUsageError",
Copy link
Contributor

Choose a reason for hiding this comment

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

Do you need to introduce this new error class in docs/exceptions.rst as well, including maybe rephrasing the "malformed calls to Globus SDK methods may raise standard python exceptions" bit?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, I think a doc update would be appropriate. Will add.

@@ -49,7 +51,7 @@ def endpoint_id(self):
if _on_windows():
appdata = os.getenv("LOCALAPPDATA")
if appdata is None:
raise ValueError(
raise GlobusSDKUsageError(
Copy link
Contributor

Choose a reason for hiding this comment

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

Is the absence of LOCALAPPDATA on a Windows system the fault of usage, or is it the fault of a broken Windows installation? I don't think it matters, and we should probably leave it alone as it would be a breaking change, but maybe an OSError would have been better here.

Copy link
Member Author

Choose a reason for hiding this comment

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

I was considering it a usage error from the start because it's not okay to try to use this method after clearing os.environ or invoking python with a really messed up env in the first place.
It's not possible for us to know why it wasn't set. So I just assume that it's the caller's fault at some level! 😄

I doubt this will ever get tripped, but #robustnessprinciple

Anyway, it sounds like you're okay with this error as it is in this PR.

@sirosen
Copy link
Member Author

sirosen commented Feb 23, 2018

The case of try: . . . except GlobusError: . . . except ValueError: . . . is interesting.

I don't want to consider this a breaking change, since cases that raised ValueError still do so.
i.e. I feel no guilt over breaking try: ... except Exception as e: if type(e) == ValueError: ...

I think there's okay precedent across most libs for adding a new error type, which may break existing error handlers, as a minor release.
It's not backwards-compatible in the strictest, most paranoid, sense, but it's probably fine for all or almost all real usage.
I'll be really surprised (and feel really dumb!) if it breaks the CLI, which is likely one of the more complex clients.

@corpulentcoffee
Copy link
Contributor

It's not backwards-compatible in the strictest, most paranoid, sense, but it's probably fine for all or almost all real usage.

Agreed; just a quick mention in release notes is fine.

The GlobusSDKUsageError is a GlobusError which is also a ValueError. It
replaces many uses of ValueError to indicate that an SDK method has been
misused. This acts as an additional hint to users that they haven't read
docs carefully enough, and makes us more conformant to our stated policy
of only raising GlobusErrors unless otherwise noted.

Include new exception in docs, and tweak text to mention its existence.

Minor fix included: sphinx was warning and skipping on one of the flow
manager objects -- fix the text on that page (which hopefully nobody is
really reading and using...) to link correctly.

Resolves globus#139
@sirosen sirosen force-pushed the feature/usage-error branch from cd34b76 to 98f4a35 Compare February 23, 2018 19:20
@sirosen
Copy link
Member Author

sirosen commented Feb 23, 2018

Rebased to include the ValueError in BaseClient.__init__ + a doc update.

@corpulentcoffee corpulentcoffee merged commit a0be7d6 into globus:master Feb 23, 2018
@sirosen sirosen mentioned this pull request Aug 28, 2018
@sirosen sirosen deleted the feature/usage-error branch May 27, 2022 22:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or improvement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants