@@ -6,45 +6,45 @@ type path = F.t
6
6
7
7
let (/ ) = F. add_unit_seg
8
8
9
- let wrap_bos =
9
+ let wrap_bos_error code =
10
10
function
11
11
| Ok r -> r
12
- | Error (`Msg msg ) -> Logger . fatal `System msg
12
+ | Error (`Msg msg ) -> Reporter . fatal code msg
13
13
14
- let get_cwd () = F. of_fpath @@ wrap_bos @@ Bos.OS.Dir. current ()
14
+ let get_cwd () = F. of_fpath @@ wrap_bos_error SystemError @@ Bos.OS.Dir. current ()
15
15
16
16
(* * Read the entire file as a string. *)
17
17
let read p =
18
- Logger . tracef " When reading the file `%a'" (F. pp ~relative_to: (get_cwd() )) p @@ fun () ->
19
- wrap_bos @@ Bos.OS.File. read (F. to_fpath p)
18
+ Reporter . tracef " when@ reading@ the@ file@ `%a'" (F. pp ~relative_to: (get_cwd() )) p @@ fun () ->
19
+ wrap_bos_error FileError @@ Bos.OS.File. read (F. to_fpath p)
20
20
21
21
(* * Write a string to a file. *)
22
22
let write p s =
23
- Logger . tracef " When writing the file `%a'" (F. pp ~relative_to: (get_cwd() )) p @@ fun () ->
24
- wrap_bos @@ Bos.OS.File. write (F. to_fpath p) s
23
+ Reporter . tracef " when@ writing@ the@ file@ `%a'" (F. pp ~relative_to: (get_cwd() )) p @@ fun () ->
24
+ wrap_bos_error FileError @@ Bos.OS.File. write (F. to_fpath p) s
25
25
26
26
let ensure_dir p =
27
- Logger . tracef " When calling `ensure_dir' on `%a'" (F. pp ~relative_to: (get_cwd() )) p @@ fun () ->
28
- ignore @@ wrap_bos @@ Bos.OS.Dir. create (F. to_fpath p)
27
+ Reporter . tracef " when@ calling@ `ensure_dir'@ on@ `%a'" (F. pp ~relative_to: (get_cwd() )) p @@ fun () ->
28
+ ignore @@ wrap_bos_error FileError @@ Bos.OS.Dir. create (F. to_fpath p)
29
29
30
30
let file_exists p =
31
- wrap_bos @@ Bos.OS.File. exists (F. to_fpath p)
31
+ wrap_bos_error FileError @@ Bos.OS.File. exists (F. to_fpath p)
32
32
33
33
let locate_anchor ~anchor start_dir =
34
- Logger . tracef " When locating the anchor `%s' from `%a'"
34
+ Reporter . tracef " when@ locating@ the@ anchor@ `%s'@ from@ `%a'"
35
35
anchor (F. pp ~relative_to: (get_cwd() )) start_dir @@ fun () ->
36
36
let rec go cwd path_acc =
37
37
if file_exists (cwd/ anchor) then
38
38
cwd, UnitPath. of_list path_acc
39
39
else
40
40
if F. is_root cwd
41
- then Logger. fatal ` AnchorNotFound " No anchor found all the way up to the root"
41
+ then Reporter. fatalf AnchorNotFound " no@ anchor@ found@ all@ the@ way@ up@ to@ the@ root"
42
42
else go (F. parent cwd) @@ F. basename cwd :: path_acc
43
43
in
44
44
go (F. to_dir_path start_dir) []
45
45
46
46
let locate_hijacking_anchor ~anchor ~root path =
47
- Logger . tracef " When checking whether there's any hijacking anchor `%s'@ between `%a' and `%a'"
47
+ Reporter . tracef " when@ checking@ whether@ there's@ any@ hijacking@ anchor@ `%s'@ between@ `%a' and@ `%a'"
48
48
anchor (F. pp ~relative_to: (get_cwd() )) root UnitPath. pp path @@ fun () ->
49
49
match UnitPath. to_list path with
50
50
| [] -> None
@@ -87,28 +87,28 @@ let guess_scheme =
87
87
end
88
88
89
89
let get_home () =
90
- F. of_fpath @@ wrap_bos @@ Bos.OS.Dir. user ()
90
+ F. of_fpath @@ wrap_bos_error MissingEnvironmentVariables @@ Bos.OS.Dir. user ()
91
91
92
92
let read_env_path var =
93
93
Result. map (F. of_fpath ~relative_to: (get_cwd () )) @@ Bos.OS.Env. path var
94
94
95
95
(* XXX I did not test the following code on different platforms. *)
96
96
let get_xdg_config_home ~app_name =
97
- Logger. trace " When calculating the XDG_CONFIG_HOME" @@ fun () ->
97
+ Reporter. tracef " when@ determining@ the@ value@ of@ XDG_CONFIG_HOME" @@ fun () ->
98
98
match read_env_path " XDG_CONFIG_HOME" with
99
99
| Ok dir -> dir/ app_name
100
100
| Error _ ->
101
101
match Lazy. force guess_scheme with
102
102
| Linux ->
103
103
let home =
104
- Logger . try_with get_home
105
- ~fatal: (fun _ -> Logger. fatal `System " Both XDG_CONFIG_HOME and HOME are not set " )
104
+ Reporter . try_with get_home
105
+ ~fatal: (fun _ -> Reporter. fatalf MissingEnvironmentVariables " both@ XDG_CONFIG_HOME@ and@ HOME@ are@ absent " )
106
106
in
107
107
home/ " .config" / app_name
108
108
| MacOS ->
109
109
let home =
110
- Logger . try_with get_home
111
- ~fatal: (fun _ -> Logger. fatal `System " Both XDG_CONFIG_HOME and HOME are not set " )
110
+ Reporter . try_with get_home
111
+ ~fatal: (fun _ -> Reporter. fatalf MissingEnvironmentVariables " both@ XDG_CONFIG_HOME@ and@ HOME@ are@ absent " )
112
112
in
113
113
home/ " Library" / " Application Support" / app_name
114
114
| Windows ->
@@ -117,33 +117,33 @@ let get_xdg_config_home ~app_name =
117
117
| Ok app_data ->
118
118
app_data/ app_name/ " config"
119
119
| Error _ ->
120
- Logger. fatal `System " Both XDG_CONFIG_HOME and APPDATA are not set "
120
+ Reporter. fatalf MissingEnvironmentVariables " both@ XDG_CONFIG_HOME@ and@ APPDATA@ are@ absent "
121
121
end
122
122
123
123
(* XXX I did not test the following code on different platforms. *)
124
124
let get_xdg_cache_home ~app_name =
125
- Logger . tracef " When calculating XDG_CACHE_HOME" @@ fun () ->
125
+ Reporter . tracef " when calculating XDG_CACHE_HOME" @@ fun () ->
126
126
match read_env_path " XDG_CACHE_HOME" with
127
127
| Ok dir -> dir/ app_name
128
128
| Error _ ->
129
129
match Lazy. force guess_scheme with
130
130
| Linux ->
131
131
let home =
132
- Logger . try_with get_home
133
- ~fatal: (fun _ -> Logger. fatal `System " Both XDG_CACHE_HOME and HOME are not set " )
132
+ Reporter . try_with get_home
133
+ ~fatal: (fun _ -> Reporter. fatalf MissingEnvironmentVariables " both@ XDG_CACHE_HOME@ and@ HOME@ are@ absent " )
134
134
in
135
135
home/ " .cache" / app_name
136
136
| MacOS ->
137
137
let home =
138
- Logger . try_with get_home
139
- ~fatal: (fun _ -> Logger. fatal `System " Both XDG_CACHE_HOME and HOME are not set " )
138
+ Reporter . try_with get_home
139
+ ~fatal: (fun _ -> Reporter. fatalf MissingEnvironmentVariables " both@ XDG_CACHE_HOME@ and@ HOME@ are@ absent " )
140
140
in
141
141
home/ " Library" / " Caches" / app_name
142
142
| Windows ->
143
143
begin
144
144
match read_env_path " LOCALAPPDATA" with
145
145
| Error _ ->
146
- Logger. fatal `System " Both XDG_CACHE_HOME and LOCALAPPDATA are not set "
146
+ Reporter. fatalf MissingEnvironmentVariables " both@ XDG_CACHE_HOME@ and@ LOCALAPPDATA@ are@ absent "
147
147
| Ok local_app_data ->
148
148
local_app_data/ app_name/ " cache"
149
149
end
@@ -158,6 +158,6 @@ let get_package_dir pkg =
158
158
FilePath. of_string @@ Findlib. package_directory pkg
159
159
with
160
160
| Findlib. No_such_package (pkg , msg ) ->
161
- Logger . fatalf `System " @[<2>No package named `%s':@ %s@]" pkg msg
161
+ Reporter . fatalf InvalidOCamlPackage " @[<2>@[no@ package@ named@ `%s':@] @ %s@]" pkg msg
162
162
| Findlib. Package_loop pkg ->
163
- Logger . fatalf `System " Package `%s' is required by itself" pkg
163
+ Reporter . fatalf InvalidOCamlPackage " package@ `%s'@ is@ requiring@ itself@ (circularity) " pkg
0 commit comments