error handling back

This commit is contained in:
yousefissa
2023-04-03 08:50:07 -07:00
parent 4416aa1aa1
commit 9ef4fab084

View File

@@ -29,14 +29,16 @@ def read_file(filename):
def write_to_file(filename, text): def write_to_file(filename, text):
filepath = safe_join(working_directory, filename) try:
directory = os.path.dirname(filepath) filepath = safe_join(working_directory, filename)
if not os.path.exists(directory): directory = os.path.dirname(filepath)
os.makedirs(directory) if not os.path.exists(directory):
with open(filepath, "w") as f: os.makedirs(directory)
f.write(text) with open(filepath, "w") as f:
return "File written to successfully." f.write(text)
return "File written to successfully."
except Exception as e:
return "Error: " + str(e)
def append_to_file(filename, text): def append_to_file(filename, text):