diff --git a/evals/elsuite/hr_ml_agent_bench/high_level_actions.py b/evals/elsuite/hr_ml_agent_bench/high_level_actions.py index 8383376367..f10c86efd2 100644 --- a/evals/elsuite/hr_ml_agent_bench/high_level_actions.py +++ b/evals/elsuite/hr_ml_agent_bench/high_level_actions.py @@ -76,7 +76,7 @@ def edit_script( # TODO: handle long file editing try: content = read_file(script_name, work_dir=work_dir, **kwargs) - except: + except Exception: write_file(script_name, "", work_dir=work_dir, **kwargs) content = "" @@ -135,12 +135,12 @@ def edit_script_lines( try: start_line_number = int(start_line_number) end_line_number = int(end_line_number) - except: + except Exception: raise EnvException("start_line_number and end_line_number must be integers") try: orig_content = read_file(script_name, work_dir=work_dir, **kwargs) - except: + except Exception: write_file(script_name, "", work_dir=work_dir, **kwargs) orig_content = "" lines = orig_content.split("\n") @@ -197,14 +197,14 @@ def inspect_script_lines(script_name, start_line_number, end_line_number, work_d try: start_line_number = int(start_line_number) end_line_number = int(end_line_number) - except: + except Exception: raise EnvException("start_line_number and end_line_number must be integers") if end_line_number - start_line_number > 100: raise EnvException("the number of lines to display is limited to 100 lines") try: # lines = open(os.path.join(work_dir,script_name)).readlines() lines = read_file(script_name, work_dir=work_dir, **kwargs).split("\n") - except: + except Exception: raise EnvException(f"cannot find script {script_name}") content = "\n".join(lines[max(int(start_line_number) - 1, 0) : int(end_line_number)]) diff --git a/evals/elsuite/hr_ml_agent_bench/low_level_actions.py b/evals/elsuite/hr_ml_agent_bench/low_level_actions.py index 10ab2c93c1..f5b09e99c7 100644 --- a/evals/elsuite/hr_ml_agent_bench/low_level_actions.py +++ b/evals/elsuite/hr_ml_agent_bench/low_level_actions.py @@ -119,7 +119,7 @@ def list_files(dir_path, work_dir=".", **kwargs): ["ls", "-F", os.path.join(work_dir, dir_path)] ).decode("utf-8") return observation - except: + except Exception: raise EnvException(f"Cannot list file in the {dir_path} directory") @@ -129,7 +129,7 @@ def read_file(file_name, work_dir=".", **kwargs): try: observation = open(os.path.join(work_dir, file_name)).read() return observation - except: + except Exception: raise EnvException(f"cannot read file {file_name}") @@ -142,7 +142,7 @@ def write_file(file_name, content, work_dir=".", **kwargs): f.write(content) observation = f"File {file_name} written successfully." return observation - except: + except Exception: raise EnvException(f"cannot write file {file_name}") @@ -155,7 +155,7 @@ def append_file(file_name, content, work_dir=".", **kwargs): f.write(content) observation = f"File {file_name} appended successfully." return observation - except: + except Exception: raise EnvException(f"cannot append file {file_name}") @@ -167,7 +167,7 @@ def copy_file(source, destination, work_dir=".", **kwargs): shutil.copyfile(os.path.join(work_dir, source), os.path.join(work_dir, destination)) observation = f"File {source} copied to {destination}" return observation - except: + except Exception: raise EnvException( f"File {source} copy to {destination} failed. Check whether the source and destinations are valid." ) @@ -189,7 +189,7 @@ def undo_edit_script(script_name, work_dir=".", **kwargs): new_content = open(os.path.join(work_dir, script_name)).read() observation = f"Content of {script_name} after undo the most recent edit:\n" + new_content return observation - except: + except Exception: raise EnvException( f"Cannot undo the edit of file name {script_name}. Check the file name again." )