Browse Source

convert Unix_error to human-readable messages on Path.mkdir_from_path (closes #10361)

Aleksandr Kuzmenko 4 years ago
parent
commit
3814232b71
2 changed files with 16 additions and 2 deletions
  1. 15 1
      src/core/path.ml
  2. 1 1
      src/macro/eval/evalStdLib.ml

+ 15 - 1
src/core/path.ml

@@ -351,7 +351,11 @@ let rec mkdir_recursive base dir_list =
 				Unix.mkdir path 0o755;
 		mkdir_recursive (if (path = "") then "/" else path) remaining
 
-let mkdir_from_path path =
+(**
+	Recursively creates `path`.
+	Raises `Unix.Unix_error` exceptions as-is.
+*)
+let mkdir_from_path_unix_err path =
 	let parts = Str.split_delim (Str.regexp "[\\/]+") path in
 	match parts with
 		| [] -> (* path was "" *) ()
@@ -359,6 +363,16 @@ let mkdir_from_path path =
 			let dir_list = List.rev (List.tl (List.rev parts)) in
 			mkdir_recursive "" dir_list
 
+(**
+	Recursively creates `path`.
+	Converts all `Unix.Unix_error` exceptions to human-readable `Failure msg`.
+*)
+let mkdir_from_path path =
+	try
+		mkdir_from_path_unix_err path
+	with Unix.Unix_error(err,_,args) ->
+		raise (Failure (Printf.sprintf "%s (%s)" (Unix.error_message err) args))
+
 let full_dot_path pack mname tname =
 	if tname = mname then (pack,mname) else (pack @ [mname],tname)
 

+ 1 - 1
src/macro/eval/evalStdLib.ml

@@ -1187,7 +1187,7 @@ module StdFileSystem = struct
 		else remove_trailing_slash s
 
 	let createDirectory = vfun1 (fun path ->
-		catch_unix_error Path.mkdir_from_path (Path.add_trailing_slash (decode_string path));
+		catch_unix_error Path.mkdir_from_path_unix_err (Path.add_trailing_slash (decode_string path));
 		vnull
 	)