Skip to content

v2.1.x Chore - Document exception nomenclature #387

Open
@coderabbitai

Description

@coderabbitai

Background

There is a consistent pattern of using _cause as the variable name when catching exceptions for chaining in the codebase, but this convention is not documented in the Exception Guide.

Proposed Change

Add the following section to the "Error Handling Practices" section of the Exception_Guide.md:

- **Exception Variable Naming**: When catching exceptions for re-raising or chaining, use `_cause` as the standard variable name. This follows PEP 8's convention for variables that might appear unused while clearly indicating the variable's purpose in exception chaining.
  # Good practice
  try:
      some_operation()
  except SomeError as _cause:
      raise CustomError("Meaningful message") from _cause

Where

https://github.com/reactive-firewall-org/multicast/blob/master/docs/Exception_Guide.md?plain=1#L308:L311

Motivation

Documenting this convention will:

  • Promote consistency across the codebase
  • Provide clear guidance for new contributors
  • Make the reason for the naming convention explicit

Related to PR #385 discussion: #385 (comment)

Metadata

Metadata

Assignees

No one assigned

    Labels

    ChoreMiscellaneous chores to maintain the projectdocumentationImprovements or additions to documentationgood first issueGood for newcomers

    Type

    Projects

    Status

    To do

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions