{"record":{"id":"d51039ba4590aee5","repo":"huggingface/smolagents","slug":"re-raise-is-not-supported-without-an-active-except","errorCode":null,"errorMessage":"Re-raise is not supported without an active exception","messagePattern":"Re-raise is not supported without an active exception","errorType":"exception","errorClass":"InterpreterError","httpStatus":null,"severity":"error","filePath":"src/smolagents/local_python_executor.py","lineNumber":1215,"sourceCode":"    static_tools: dict[str, Callable],\n    custom_tools: dict[str, Callable],\n    authorized_imports: list[str],\n) -> None:\n    if raise_node.exc is not None:\n        exc = evaluate_ast(raise_node.exc, state, static_tools, custom_tools, authorized_imports)\n    else:\n        exc = None\n    if raise_node.cause is not None:\n        cause = evaluate_ast(raise_node.cause, state, static_tools, custom_tools, authorized_imports)\n    else:\n        cause = None\n    if exc is not None:\n        if cause is not None:\n            raise exc from cause\n        else:\n            raise exc\n    else:\n        raise InterpreterError(\"Re-raise is not supported without an active exception\")\n\n\ndef evaluate_assert(\n    assert_node: ast.Assert,\n    state: dict[str, Any],\n    static_tools: dict[str, Callable],\n    custom_tools: dict[str, Callable],\n    authorized_imports: list[str],\n) -> None:\n    test_result = evaluate_ast(assert_node.test, state, static_tools, custom_tools, authorized_imports)\n    if not test_result:\n        if assert_node.msg:\n            msg = evaluate_ast(assert_node.msg, state, static_tools, custom_tools, authorized_imports)\n            raise AssertionError(msg)\n        else:\n            # Include the failing condition in the assertion message\n            test_code = ast.unparse(assert_node.test)\n            raise AssertionError(f\"Assertion failed: {test_code}\")","sourceCodeStart":1197,"sourceCodeEnd":1233,"githubUrl":"https://github.com/huggingface/smolagents/blob/30bb1161095dbae2271e6bc3cc4c219cc3897a57/src/smolagents/local_python_executor.py#L1197-L1233","documentation":"The code contains a bare `raise` outside any except block with an active exception. The sandboxed interpreter does not track a current exception, so it cannot re-raise.","triggerScenarios":"A bare `raise;` statement executed when no exception is being handled — e.g. in a finally block, in a nested function called from inside except, or after the except block ended.","commonSituations":"Agent code wraps `raise` in a helper function intending to propagate; using `raise` inside `finally` to re-raise; refactored except-block code into a function so Python's implicit exception context is lost.","solutions":["Capture the exception first: except X as e: ... then `raise e` explicitly instead of bare `raise`","Move the bare raise inside the except block in the same function scope","Re-raise with raise ExceptionClass(args) if the original exception object isn't available"],"exampleFix":"# before\ntry:\n    risky()\nexcept ValueError:\n    log('failed')\nfinally:\n    raise  # invalid here\n# after\ntry:\n    risky()\nexcept ValueError as e:\n    log('failed')\n    raise e","handlingStrategy":"try-catch","validationCode":"# always bind and re-raise explicitly in generated code\ntry:\n    risky()\nexcept Exception as e:\n    raise e","typeGuard":null,"tryCatchPattern":"try:\n    evaluate_python(code, ...)\nexcept InterpreterError as e:\n    if 'Re-raise is not supported' in str(e):\n        # rewrite bare `raise` to `raise e` inside except and retry","preventionTips":["Never use bare raise outside an except block in the same function scope","Bind exceptions with `as e` and re-raise explicitly"],"tags":["python-executor","raise","exception-handling","smolagents"],"backgroundTag":"bare-raise-without-active-exception","analyzedSha":"30bb1161095dbae2271e6bc3cc4c219cc3897a57","analyzedAt":"2026-08-28T18:52:54.169Z","schemaVersion":2},"datasetVersion":"2026-08-28T21:17:43.275Z"}