Skip to content

Commit f65ba51

Browse files
committed
Use ensure_dir to ensure directories exist + output more verbose error message
Signed-off-by: Michael Oviedo <mikeovi@amazon.com>
1 parent bb2df83 commit f65ba51

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

osbenchmark/paths.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,27 +22,29 @@
2222
# specific language governing permissions and limitations
2323
# under the License.
2424
import os
25-
25+
import sys
26+
from osbenchmark.utils.io import ensure_dir
2627

2728
def benchmark_confdir():
2829
default_home = os.path.expanduser("~")
2930
old_path = os.path.join(default_home, ".benchmark")
3031
new_path = os.path.join(default_home, ".osb")
3132

32-
# Create .benchmark directory if it doesn't exist
33-
if not os.path.exists(old_path):
34-
os.makedirs(old_path, exist_ok=True)
35-
36-
# Create .osb directory if it doesn't exist
37-
if not os.path.exists(new_path):
38-
os.makedirs(new_path, exist_ok=True)
33+
# ensure both directories exist
34+
ensure_dir(old_path)
35+
ensure_dir(new_path)
3936

4037
# Create symlink from .osb to .benchmark if it doesn't exist
4138
if not os.path.islink(new_path):
4239
try:
4340
os.symlink(old_path, new_path, target_is_directory=True)
44-
except OSError:
45-
print(f"Warning: Failed to create symlink from {new_path} to {old_path}")
41+
except OSError as e:
42+
error_message = (
43+
f"OSError: Failed to create symlink from {new_path} to {old_path}\n"
44+
f"Error type: {type(e).__name__}\n"
45+
f"Error message: {str(e)}\n"
46+
)
47+
print(error_message, file=sys.stderr)
4648

4749
return os.path.join(os.getenv("BENCHMARK_HOME", default_home), ".osb")
4850

0 commit comments

Comments
 (0)