Closed
Description
Standardize error handling approach.
While the error handling is thorough, there are inconsistencies in the approach:
Error variable naming varies (ImportErr vs _cause)
Some errors are explicitly cleaned up while others aren't
Consider standardizing the approach:
try:
try:
import context
- except Exception as ImportErr: # pragma: no branch
- ImportErr = None
- del ImportErr # skipcq - cleanup any error leaks early
+ except Exception as _cause: # pragma: no branch
+ del _cause # skipcq - cleanup any error leaks early
from . import context
if context.__name__ is None:
raise ImportError("[CWE-758] Failed to import context") from None
else:
from context import sys
from context import os
from context import unittest
-except Exception as _cause: # pragma: no branch
- raise ImportError("[CWE-758] Failed to import test context") from _cause
+except Exception as baton: # pragma: no branch
+ raise ImportError("[CWE-758] Failed to import test context") from baton
- name caught exceptions
_cause
or_root_cause
when handled_cause
s should not be documented in the docstrings; handler behavior may be documented on a case by case basis_cause
s should be preemptively cleaned up_cause
s may be chained, instead of cleaned up, when raising exceptions caused by_cause
_root_cause
s may be used in nested try-catch to avoid name shadowing_cause
s
- name caught exceptions
baton
when chaining errorsbaton
s should be documented in the docstringsbaton
s should never be preemptively cleaned up
Metadata
Metadata
Assignees
Labels
Type
Projects
Status
Archive Backlog