Skip to content

AutoGPT is the vision of accessible AI for everyone, to use and to build on. Our mission is to provide the tools, so that you can focus on what matters.

error handling back

yousefissa9ef4fab08463
diff --git a/scripts/file_operations.py b/scripts/file_operations.py
index d7c7a1b082..81ad471577 100644
--- a/scripts/file_operations.py
+++ b/scripts/file_operations.py
@@ -29,14 +29,16 @@ def read_file(filename):
def write_to_file(filename, text):
- filepath = safe_join(working_directory, filename)
- directory = os.path.dirname(filepath)
- if not os.path.exists(directory):
- os.makedirs(directory)
- with open(filepath, "w") as f:
- f.write(text)
- return "File written to successfully."
-
+ try:
+ filepath = safe_join(working_directory, filename)
+ directory = os.path.dirname(filepath)
+ if not os.path.exists(directory):
+ os.makedirs(directory)
+ with open(filepath, "w") as f:
+ f.write(text)
+ return "File written to successfully."
+ except Exception as e:
+ return "Error: " + str(e)
def append_to_file(filename, text):