{"record":{"id":"f3cb08d750e0ea48","repo":"iflytek/astron-agent","slug":"code-execution-error-self-remove-traceback-stdin-line-resp","errorCode":"CODE_EXECUTION_ERROR","errorMessage":"self._remove_traceback_stdin_line(resp_message)","messagePattern":"self\\._remove_traceback_stdin_line\\(resp_message\\)","errorType":"error_code","errorClass":"CustomExceptionCD","httpStatus":null,"severity":"error","filePath":"core/workflow/engine/nodes/code/executor/ifly/ifly_executor_v2.py","lineNumber":143,"sourceCode":"        Handle error response and raise appropriate exception.\n\n        :param resp_json: Response json dictionary\n        :param span: Tracing span for logging\n        :raises CustomExceptionCD: Based on error type\n        \"\"\"\n\n        err_type = resp_json.get(\"type\", \"\")\n        resp_message = resp_json.get(\"message\", \"\")\n        span.add_error_event(f\"err_type: {err_type}\")\n        span.add_error_event(f\"response message: {resp_message}\")\n\n        if err_type == \"exec_code_timeout\":\n            raise CustomExceptionCD(\n                err_code=CodeEnum.CODE_EXECUTION_TIMEOUT_ERROR.code,\n                err_msg=\"Code execution timeout\",\n            )\n        elif err_type == \"exec_code_failed\":\n            raise CustomExceptionCD(\n                err_code=CodeEnum.CODE_EXECUTION_ERROR.code,\n                err_msg=self._remove_traceback_stdin_line(resp_message),\n            )\n        else:\n            raise CustomExceptionCD(\n                err_code=CodeEnum.CODE_EXECUTION_ERROR.code,\n                err_msg=\"Code execution failed\",\n            )\n\n    def _remove_traceback_stdin_line(self, traceback_str: str) -> str:\n        \"\"\"\n        Remove traceback line with V2-specific preprocessing.\n\n        Extends parent method by first extracting error message after\n        'exec code error:' prefix before removing stdin traceback line.\n\n        :param traceback_str: String containing traceback information\n        :return: String with the specified traceback line removed","sourceCodeStart":125,"sourceCodeEnd":161,"githubUrl":"https://github.com/iflytek/astron-agent/blob/5e758547a83371a5a4b29dadf4ac03e8dd527635/core/workflow/engine/nodes/code/executor/ifly/ifly_executor_v2.py#L125-L161","documentation":"CODE_EXECUTION_ERROR raised when the iFly v2 code service returns type == 'exec_code_failed'. The err_msg is the service's response message passed through _remove_traceback_stdin_line, which strips the noisy stdin line from the traceback so the message reflects the actual exception in the user's code.","triggerScenarios":"The user code inside a code node raised an unhandled exception (NameError, KeyError, ImportError, syntax error, division by zero, etc.) and the sandbox reported exec_code_failed with the Python traceback as the message.","commonSituations":"Typos or missing imports in code-node scripts; assuming an upstream variable exists when the producing node failed or renamed an output; dependency unavailable inside the sandbox; calling code with wrong variable types from the workflow.","solutions":["Read the err_msg traceback in the workflow run detail; it shows the exact line and exception in the user code.","Fix the bug in the code-node script (missing import, wrong variable name, unhandled None/empty input).","Guard inputs from upstream nodes (check for None/empty before indexing) since node failures can feed incomplete data.","Verify required packages exist in the sandbox image or vendor/declare the dependency."],"exampleFix":"# before (user code)\nresult = data[\"total\"] / count\n// after\ntotal = data.get(\"total\", 0)\nif not count:\n    result = 0\nelse:\n    result = total / count","handlingStrategy":"try-catch","validationCode":"# guard upstream inputs the code node will consume\nassert isinstance(variable_pool.get(\"data\"), dict) and variable_pool.get(\"data\"), \"upstream data missing before code node\"","typeGuard":"def is_safe_name(code: str) -> bool:\n    import ast\n    try:\n        ast.parse(code)\n        return True\n    except SyntaxError:\n        return False","tryCatchPattern":"try:\n    output = await executor.execute(...)\nexcept CustomExceptionCD as e:\n    if e.err_code == CodeEnum.CODE_EXECUTION_ERROR.code:\n        logger.error(\"user code failed: %s\", e.err_msg)  # err_msg carries cleaned traceback\n        output = error_placeholder","preventionTips":["Test code-node scripts with empty/None upstream outputs before publishing","Use .get() with defaults instead of direct key access on upstream data","Verify imports exist in the sandbox image"],"tags":["code-execution","python","traceback","workflow"],"backgroundTag":"code-execution-failed","analyzedSha":"5e758547a83371a5a4b29dadf4ac03e8dd527635","analyzedAt":"2026-09-12T08:03:51.356Z","contentChangedAt":"2026-09-12T08:03:51.356Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}