Skip to content

Commit a67adb8

Browse files
pkg: Improve fetch error messages (#12490)
* Use `command` for referring to the curl binary Signed-off-by: Marek Kubica <[email protected]> * Make casing of error messages more consistent Signed-off-by: Marek Kubica <[email protected]> --------- Signed-off-by: Marek Kubica <[email protected]>
1 parent b88950d commit a67adb8

File tree

4 files changed

+43
-18
lines changed

4 files changed

+43
-18
lines changed

src/dune_pkg/fetch.ml

Lines changed: 37 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,26 @@ module Curl = struct
77
(match Bin.which ~path:(Env_path.path Env.initial) "curl" with
88
| Some p -> p
99
| None ->
10+
let curl = User_message.command "curl" in
11+
let sep = Pp.space in
1012
User_error.raise
11-
~hints:[ Pp.text "Install curl with your system package manager." ]
12-
[ Pp.text
13-
"The program \"curl\" does not appear to be installed. Dune uses curl to \
14-
download packages. Dune requires that the \"curl\" executable be located \
15-
in one of the directories listed in the PATH variable."
13+
~hints:
14+
[ Pp.concat
15+
~sep
16+
[ Pp.text "Install"; curl; Pp.text "with your system package manager." ]
17+
]
18+
[ Pp.concat
19+
~sep
20+
[ Pp.text "The program"
21+
; curl
22+
; Pp.text "does not appear to be installed. Dune uses"
23+
; curl
24+
; Pp.text "to download packages. Dune requires that the"
25+
; curl
26+
; Pp.text
27+
"executable be located in one of the directories listed in the PATH \
28+
variable."
29+
]
1630
])
1731
;;
1832

@@ -89,14 +103,20 @@ module Curl = struct
89103
[ Pp.text s ]
90104
| exception s ->
91105
[ Pp.textf
92-
"failed to read stderr form file %s"
106+
"Failed to read stderr from file %s"
93107
(Path.to_string_maybe_quoted stderr)
94108
; Exn.pp s
95109
]
96110
in
97111
Error
98112
(User_message.make
99-
([ Pp.textf "curl returned an invalid error code %d" exit_code ] @ stderr)))
113+
([ Pp.concat
114+
~sep:Pp.space
115+
[ User_message.command "curl"
116+
; Pp.textf "returned an invalid error code %d" exit_code
117+
]
118+
]
119+
@ stderr)))
100120
else (
101121
Path.unlink_no_err stderr;
102122
match
@@ -108,12 +128,17 @@ module Curl = struct
108128
| None ->
109129
Error
110130
(User_message.make
111-
[ Pp.textf "curl returned an HTTP code we don't understand: %S" http_code ])
131+
[ Pp.concat
132+
~sep:Pp.space
133+
[ User_message.command "curl"
134+
; Pp.textf "returned an HTTP code we don't understand: %S" http_code
135+
]
136+
])
112137
| Some http_code ->
113138
if http_code = 200
114139
then Ok ()
115140
else
116-
Error (User_message.make [ Pp.textf "download failed with code %d" http_code ]))
141+
Error (User_message.make [ Pp.textf "Download failed with code %d" http_code ]))
117142
;;
118143
end
119144
@@ -126,7 +151,7 @@ let label = "dune-fetch"
126151
let unpack_archive ~archive_driver ~target ~archive =
127152
Archive_driver.extract archive_driver ~archive ~target
128153
>>| Result.map_error ~f:(fun () ->
129-
Pp.textf "unable to extract %S" (Path.to_string archive))
154+
Pp.textf "Unable to extract %s" (Path.to_string_maybe_quoted archive))
130155
;;
131156
132157
let check_checksum checksum path =
@@ -180,9 +205,9 @@ let fetch_curl ~unpack:unpack_flag ~checksum ~target (url : OpamUrl.t) =
180205
let exn =
181206
User_message.make
182207
[ Pp.textf
183-
"failed to unpack archive downloaded from %s"
208+
"Failed to unpack archive downloaded from %s"
184209
(OpamUrl.to_string url)
185-
; Pp.text "reason:"
210+
; Pp.text "Reason:"
186211
; msg
187212
]
188213
in

test/blackbox-tests/test-cases/pkg/compute-checksums-when-missing.t

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ Recreate the foo package with a fake port number to signal that the file will
5151
Package "foo" has source archive which lacks a checksum.
5252
The source archive will be downloaded from: http://0.0.0.0:9000
5353
Dune will compute its own checksum for this source archive.
54-
Warning: download failed with code 404
54+
Warning: Download failed with code 404
5555
Solution for dune.lock:
5656
- foo.0.0.1
5757
$ cat ${default_lock_dir}/foo.pkg

test/blackbox-tests/test-cases/pkg/curl-not-installed.t

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ Build the package in an environment without curl.
1919
File "dune.lock/foo.pkg", line 3, characters 7-28:
2020
3 | (url "http://0.0.0.0:8000")))
2121
^^^^^^^^^^^^^^^^^^^^^
22-
Error: The program "curl" does not appear to be installed. Dune uses curl to
23-
download packages. Dune requires that the "curl" executable be located in one
24-
of the directories listed in the PATH variable.
25-
Hint: Install curl with your system package manager.
22+
Error: The program 'curl' does not appear to be installed. Dune uses 'curl'
23+
to download packages. Dune requires that the 'curl' executable be located in
24+
one of the directories listed in the PATH variable.
25+
Hint: Install 'curl' with your system package manager.
2626
[1]

test/blackbox-tests/test-cases/pkg/fetch-cache.t

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ cache, it will fail, as the source is 404 now:
4848
File "dune.lock/test.pkg", line 4, characters 7-25:
4949
4 | (url http://localhost:1)
5050
^^^^^^^^^^^^^^^^^^
51-
Error: download failed with code 404
51+
Error: Download failed with code 404
5252
5353
[1]
5454

0 commit comments

Comments
 (0)