Skip to content

v2.0.x Chore - Consider: Standardize error handling approach. #271

Closed
@reactive-firewall

Description

@reactive-firewall

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
  1. name caught exceptions _cause or _root_cause when handled
    • _causes should not be documented in the docstrings; handler behavior may be documented on a case by case basis
    • _causes should be preemptively cleaned up
    • _causes may be chained, instead of cleaned up, when raising exceptions caused by _cause
    • _root_causes may be used in nested try-catch to avoid name shadowing _causes
  2. name caught exceptions baton when chaining errors
    • batons should be documented in the docstrings
    • batons should never be preemptively cleaned up

Metadata

Metadata

Labels

ChoreMiscellaneous chores to maintain the projectMulticastAny main project file changesPython LangChanges to Python source code

Type

No type

Projects

Status

Archive Backlog

Relationships

None yet

Development

No branches or pull requests

Issue actions