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

[iot] Don't swallow exceptions in the code samples. #3424

Closed
tmatsuo opened this issue Apr 17, 2020 · 0 comments · Fixed by #3425
Closed

[iot] Don't swallow exceptions in the code samples. #3424

tmatsuo opened this issue Apr 17, 2020 · 0 comments · Fixed by #3425
Assignees

Comments

@tmatsuo
Copy link
Contributor

tmatsuo commented Apr 17, 2020

Related to #2861

We need to add bunch of fixtures for more robust tests. However, this is difficult now because the current sample code often does something like this:

    try:
        response = client.create_device_registry(parent, body)
        print('Created registry')
        return response
    except HttpError:
        print('Error, registry not created')
        return ""
    except AlreadyExists:
        print('Error, registry already exists')
        return ""

This is bad because of the following reasons:

  1. It throws away all the details about the exception.
  2. The caller can not distinguish HttpError from AlreadyExists because the return values are the same.

I think we should re-raise the exception (it's good to have these except clauses to show how to handle exceptions).

I'm going to fix it first before building the fixture for #2861

@gguuss FYI

@tmatsuo tmatsuo self-assigned this Apr 17, 2020
tmatsuo pushed a commit to tmatsuo/python-docs-samples that referenced this issue Apr 17, 2020
tmatsuo pushed a commit that referenced this issue Apr 17, 2020
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 a pull request may close this issue.

1 participant