Skip to content

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

@tmatsuo

Description

@tmatsuo

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

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions