From 5bb5722921e4a6f3a3706aa1cfb5ed21576b4b0f Mon Sep 17 00:00:00 2001 From: Tim Date: Fri, 6 Jun 2025 11:45:48 +0800 Subject: [PATCH] fix: conda error information (#941) * test with conda error * reformat --- rdagent/utils/env.py | 7 ++++--- test/utils/test_env.py | 12 ++++++++++++ 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/rdagent/utils/env.py b/rdagent/utils/env.py index d3623908..178ca20e 100644 --- a/rdagent/utils/env.py +++ b/rdagent/utils/env.py @@ -445,9 +445,10 @@ class LocalEnv(Env[ASpecificLocalConf]): Console().print(output.strip(), markup=False) combined_output += output elif fd == stderr_fd: - error = process.stderr.readline() - if error: - Console().print(error.strip(), markup=False) + chunk = os.read(stderr_fd, 4096) + if chunk: + error = chunk.decode(errors="replace") + Console().print(error, end="", markup=False) combined_output += error # Capture any final output diff --git a/test/utils/test_env.py b/test/utils/test_env.py index 66a1c7c0..cca2dd01 100644 --- a/test/utils/test_env.py +++ b/test/utils/test_env.py @@ -1,5 +1,6 @@ import os import sys +import time import unittest from pathlib import Path @@ -69,6 +70,17 @@ class EnvUtils(unittest.TestCase): res, code = le.run_ret_code(local_path=str(code_path)) print(res, code) + def test_conda_error(self): + conda_conf = CondaConf(conda_env_name="MLE") + le = LocalEnv(conf=conda_conf) + le.prepare() + file_name = f"{time.time()}.py" + with open(self.test_workspace / file_name, "w") as f: + f.write('import json \njson.loads(b\'{"name": "\xa1"}\')') + res, code = le.run_ret_code(local_path=str(self.test_workspace), entry=f"python {file_name}") + assert code == 1 + assert "bytes can only contain ASCII literal characters" in res + def test_docker(self): """We will mount `env_tpl` into the docker image. And run the docker image with `qrun conf.yaml`