Skip to content

Commit f5bb16e

Browse files
committed
Error handling for dir creation
1 parent acc6980 commit f5bb16e

File tree

1 file changed

+16
-9
lines changed

1 file changed

+16
-9
lines changed

eburger/utils/filesystem.py

+16-9
Original file line numberDiff line numberDiff line change
@@ -96,24 +96,31 @@ def create_directory_if_not_exists(directory_path: Path):
9696
# Check if the directory already exists
9797
if not os.path.exists(directory_path):
9898
# Create the directory
99-
os.makedirs(directory_path)
100-
log("debug", f"Created directory: {directory_path}")
99+
try:
100+
os.makedirs(directory_path)
101+
log("debug", f"Created directory: {directory_path}")
102+
except Exception as e:
103+
log("error", f"Could not create direction {directory_path}. {e}")
101104

102105

103106
def create_or_empty_directory(directory_path: Path):
104107
# Check if the directory already exists
105108
if os.path.exists(directory_path):
106109
# Empty the directory by removing all its contents
107110
shutil.rmtree(directory_path)
108-
os.makedirs(directory_path)
109-
log(
110-
"debug",
111-
f"Emptied and re-created directory: {directory_path}",
112-
)
111+
112+
try:
113+
os.makedirs(directory_path)
114+
log("debug", f"Emptied and re-created directory: {directory_path}")
115+
except Exception as e:
116+
log("error", f"Could not create direction {directory_path}. {e}")
113117
else:
114118
# Create the directory if it does not exist
115-
os.makedirs(directory_path)
116-
log("debug", f"Created directory: {directory_path}")
119+
try:
120+
os.makedirs(directory_path)
121+
log("debug", f"Created directory: {directory_path}")
122+
except Exception as e:
123+
log("error", f"Could not create direction {directory_path}. {e}")
117124

118125

119126
# TODO: Add better handling for multiple build info files

0 commit comments

Comments
 (0)