coze-dev / coze-dev/coze-studio
换行符\n在工作流里代码组件python代码执行报错
- Dominant language
- TypeScript
- Stars
- 21.6k
- Forks
- 3.1k
- PR merge metrics
- No merged PRs in 30d
Description
- 代码组件执行以下脚本:
```python
async def main(args: Args) -> Output:
params = args.params
title = params['title']
summary = params['summary']
chapters = params['chapters']
article = title + '\n\n' + summary + '\n\n' + '\n\n'.join(chapters)
# 构建输出对象
ret: Output = {
"article": article
}
return ret
```
- 直接报错,错误信息:
```
{
"$error": "Function execution failed, please check the code of the function. Detail: exec failed, stdout=, stderr=Traceback (most recent call last):\n File \"/lib/python312.zip/_pyodide/_base.py\", line 597, in eval_code_async\n await CodeRunner(\n ^^^^^^^^^^^\n File \"/lib/python312.zip/_pyodide/_base.py\", line 285, in __init__\n self.ast = next(self._gen)\n ^^^^^^^^^^^^^^^\n File \"/lib/python312.zip/_pyodide/_base.py\", line 149, in _parse_and_compile_gen\n mod = compile(source, filename, mode, flags | ast.PyCF_ONLY_AST)\n ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n File \"\", line 13\n args={\"chapters\": [{\"chapter\": \"# \\u7b2c1\\u7ae0 MCP\\u670d\\u52a1\\u6838\\u5fc3\\u6982\\u5ff5\\u89e3\\u6790 \\ud83e\\udde0\n ^\nSyntaxError: unterminated string literal (detected at line 13)\n, sandbox_err="
}
```
- 猜测sandbox在执行代码时,对代码进行了转义,导致\n变成了的代码换行符
Contributor guide
Research direction
Reproduce the failure in a workflow code component using the provided Python script and chapter content containing newlines. Start at the sandbox execution path shown in the traceback, especially Pyodide's eval_code_async and the generated args value, and trace how the input is escaped before compilation. Done means newline-containing chapter data executes without an unterminated string literal error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100