Skip to content

Replace except: and except Exception: with a more granular exception #2550

@parthea

Description

@parthea

See feedback from gemini in PR #2549:

#2549 (comment)

The except: on the next line is a bare except, which is a bad practice as it catches all exceptions, including system-exiting ones like SystemExit and KeyboardInterrupt. This can make debugging difficult and hide underlying issues. It would be better to catch a more specific exception, like Exception.

While there's a TODO in the template to remove this try/except block, improving it in the meantime would be beneficial.

This change should be applied to the template file: gapic/templates/%namespace/%name_%version/%sub/services/%service/_shared_macros.j2.

Suggested change in the template:

        except Exception:

We should remove all usages of except: and replace them with except Exception: or a more granular exception

Search results for except:

https://github.com/search?q=repo%3Agoogleapis%2Fgapic-generator-python%20except%3A&type=code

Search results for except Exception:
https://github.com/search?q=repo%3Agoogleapis%2Fgapic-generator-python+%22except+Exception%3A%22&type=code

Metadata

Metadata

Assignees

No one assigned

    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