()
| 1637 | |
| 1638 | # Define the actual execution logic |
| 1639 | def _execute_code(): |
| 1640 | result = None |
| 1641 | try: |
| 1642 | for node in expression.body: |
| 1643 | result = evaluate_ast(node, state, static_tools, custom_tools, authorized_imports) |
| 1644 | state["_print_outputs"].value = truncate_content( |
| 1645 | str(state["_print_outputs"]), max_length=max_print_outputs_length |
| 1646 | ) |
| 1647 | is_final_answer = False |
| 1648 | return result, is_final_answer |
| 1649 | except FinalAnswerException as e: |
| 1650 | state["_print_outputs"].value = truncate_content( |
| 1651 | str(state["_print_outputs"]), max_length=max_print_outputs_length |
| 1652 | ) |
| 1653 | is_final_answer = True |
| 1654 | return e.value, is_final_answer |
| 1655 | except Exception as e: |
| 1656 | state["_print_outputs"].value = truncate_content( |
| 1657 | str(state["_print_outputs"]), max_length=max_print_outputs_length |
| 1658 | ) |
| 1659 | raise InterpreterError( |
| 1660 | f"Code execution failed at line '{ast.get_source_segment(code, node)}' due to: {type(e).__name__}: {e}" |
| 1661 | ) |
| 1662 | |
| 1663 | # Apply timeout if specified |
| 1664 | if timeout_seconds is not None: |
no test coverage detected
searching dependent graphs…