Description
In visit_uri() within minecode/management/commands/run_visit.py, the exception variable e is referenced outside the except block where it is defined.
Inside the try/except block, the variable e is created only when an exception occurs:
except (ConnectionError, Timeout, Exception) as e:
msg = f"Visit error for URI: {uri_to_visit}"
msg += "\n".format()
msg += get_error_message(e)
visit_errors.append(msg)
logger.error(msg)
Later in the function, e is used again inside the if visit_error: block:
if visit_error:
msg = f"Visit error for URI: {uri_to_visit}"
msg += "\n".format()
msg += get_error_message(e) # NOQA
However, this block can execute even when no exception was raised. In such cases, the variable e is not defined, which results in a runtime error:
NameError: name 'e' is not defined
This happens when _visit_router.process(uri_to_visit) returns a visit_error value without raising an exception.
Additionally, the # NOQA comment suppresses lint warnings that would otherwise highlight this issue.
To fix this, the code should avoid referencing e outside the except block and instead use the visit_error value or store the exception in a variable defined before the try block.
Description
In
visit_uri()withinminecode/management/commands/run_visit.py, the exception variableeis referenced outside theexceptblock where it is defined.Inside the
try/exceptblock, the variableeis created only when an exception occurs:Later in the function,
eis used again inside theif visit_error:block:However, this block can execute even when no exception was raised. In such cases, the variable
eis not defined, which results in a runtime error:This happens when
_visit_router.process(uri_to_visit)returns avisit_errorvalue without raising an exception.Additionally, the
# NOQAcomment suppresses lint warnings that would otherwise highlight this issue.To fix this, the code should avoid referencing
eoutside theexceptblock and instead use thevisit_errorvalue or store the exception in a variable defined before thetryblock.