Skip to content

Commit da06f1d

Browse files
rjboukit-ty-kate
authored andcommitted
Improve the error message in case of missing or bad hash of extra-file
1 parent 4db3e2a commit da06f1d

File tree

3 files changed

+69
-27
lines changed

3 files changed

+69
-27
lines changed

master_changes.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ users)
2626
## Actions
2727

2828
## Install
29+
* More fine grained error message in case of bad hash or missing extra-files error (and remove raw fatal error) [#6696 @rjbou]
2930

3031
## Build (package)
3132

@@ -56,6 +57,7 @@ users)
5657

5758
## Source
5859
* Better error message, especially in case of `Failure` [#6696 @rjbou]
60+
* Raise a warning instead of an error when an item of `extra-files` is missing [#6696 @rjbou]
5961

6062
## Lint
6163

src/client/opamAction.ml

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -495,17 +495,37 @@ let prepare_package_source st nv dir =
495495
else None)
496496
xs
497497
in
498-
let bad_hash =
499-
List.filter_map (fun (src, base, hash) ->
500-
if OpamHash.check_file (OpamFilename.to_string src) hash then
501-
(OpamFilename.copy ~src ~dst:(OpamFilename.create dir base); None)
498+
let bad_hash, missing =
499+
List.fold_left (fun (bad_hash, missing) (src, base, hash) ->
500+
if OpamFilename.exists src then
501+
let file = OpamFilename.to_string src in
502+
if OpamHash.check_file file hash then
503+
(OpamFilename.copy ~src ~dst:(OpamFilename.create dir base);
504+
bad_hash, missing)
505+
else
506+
(src::bad_hash), missing
502507
else
503-
Some src) extra_files
508+
bad_hash, (src::missing))
509+
([], []) extra_files
510+
in
511+
let bad_hash_msg bad_hash =
512+
Printf.sprintf "%s: Bad hash for extra-file\n%s"
513+
(OpamPackage.to_string nv)
514+
(OpamStd.Format.itemize OpamFilename.to_string bad_hash)
515+
in
516+
let missing_msg missing =
517+
Printf.sprintf "%s: Missing extra-file for\n%s"
518+
(OpamPackage.to_string nv)
519+
(OpamStd.Format.itemize OpamFilename.to_string missing)
504520
in
505-
if bad_hash = [] then None else
506-
Some (Failure
507-
(Printf.sprintf "Bad hash for %s"
508-
(OpamStd.Format.itemize OpamFilename.to_string bad_hash)));
521+
match bad_hash, missing with
522+
| [], [] -> None
523+
| _::_ as bad_hash, [] ->
524+
Some (Failure (bad_hash_msg bad_hash))
525+
| [], (_::_ as missing) ->
526+
Some (Failure (missing_msg missing))
527+
| bad_hash, missing ->
528+
Some (Failure (bad_hash_msg bad_hash ^ "\n" ^ missing_msg missing))
509529
in
510530
OpamFilename.mkdir dir;
511531
get_extra_sources_job @@+ function Some _ as err -> Done err | None ->

tests/reftests/extrafile.test

Lines changed: 38 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,8 @@ The following actions will be performed:
260260

261261
<><> Processing actions <><><><><><><><><><><><><><><><><><><><><><><><><><><><>
262262

263-
Bad hash for - ${BASEDIR}/OPAM/repo/default/packages/bad-md5/bad-md5.1/files/p.patch
263+
bad-md5.1: Bad hash for extra-file
264+
- ${BASEDIR}/OPAM/repo/default/packages/bad-md5/bad-md5.1/files/p.patch
264265

265266

266267

@@ -277,7 +278,8 @@ The following actions will be performed:
277278

278279
<><> Processing actions <><><><><><><><><><><><><><><><><><><><><><><><><><><><>
279280

280-
Bad hash for - ${BASEDIR}/OPAM/repo/default/packages/bad-md5/bad-md5.1/files/p.patch
281+
bad-md5.1: Bad hash for extra-file
282+
- ${BASEDIR}/OPAM/repo/default/packages/bad-md5/bad-md5.1/files/p.patch
281283

282284

283285

@@ -289,15 +291,17 @@ Bad hash for - ${BASEDIR}/OPAM/repo/default/packages/bad-md5/bad-md5.1/files/p
289291
# Return code 31 #
290292
### opam source bad-md5 | '.n"' -> '"'
291293
[WARNING] Some errors extracting to ${BASEDIR}/bad-md5.1:
292-
Bad hash for - ${BASEDIR}/OPAM/repo/default/packages/bad-md5/bad-md5.1/files/p.patch
294+
bad-md5.1: Bad hash for extra-file
295+
- ${BASEDIR}/OPAM/repo/default/packages/bad-md5/bad-md5.1/files/p.patch
293296

294297

295298
### test -f bad-md5.1/p.patch
296299
# Return code 1 #
297300
### rm -r bad-md5.1
298301
### opam source bad-md5 --require-checksums | '.n"' -> '"'
299302
[WARNING] Some errors extracting to ${BASEDIR}/bad-md5.1:
300-
Bad hash for - ${BASEDIR}/OPAM/repo/default/packages/bad-md5/bad-md5.1/files/p.patch
303+
bad-md5.1: Bad hash for extra-file
304+
- ${BASEDIR}/OPAM/repo/default/packages/bad-md5/bad-md5.1/files/p.patch
301305

302306

303307
### test -f bad-md5.1/p.patch
@@ -320,7 +324,8 @@ The following actions will be performed:
320324

321325
<><> Processing actions <><><><><><><><><><><><><><><><><><><><><><><><><><><><>
322326

323-
Bad hash for - ${BASEDIR}/OPAM/repo/default/packages/good-md5-bad-sha256/good-md5-bad-sha256.1/files/p.patch
327+
good-md5-bad-sha256.1: Bad hash for extra-file
328+
- ${BASEDIR}/OPAM/repo/default/packages/good-md5-bad-sha256/good-md5-bad-sha256.1/files/p.patch
324329

325330

326331

@@ -337,7 +342,8 @@ The following actions will be performed:
337342

338343
<><> Processing actions <><><><><><><><><><><><><><><><><><><><><><><><><><><><>
339344

340-
Bad hash for - ${BASEDIR}/OPAM/repo/default/packages/good-md5-bad-sha256/good-md5-bad-sha256.1/files/p.patch
345+
good-md5-bad-sha256.1: Bad hash for extra-file
346+
- ${BASEDIR}/OPAM/repo/default/packages/good-md5-bad-sha256/good-md5-bad-sha256.1/files/p.patch
341347

342348

343349

@@ -349,14 +355,16 @@ Bad hash for - ${BASEDIR}/OPAM/repo/default/packages/good-md5-bad-sha256/good-
349355
# Return code 31 #
350356
### opam source good-md5-bad-sha256 | '.n"' -> '"'
351357
[WARNING] Some errors extracting to ${BASEDIR}/good-md5-bad-sha256.1:
352-
Bad hash for - ${BASEDIR}/OPAM/repo/default/packages/good-md5-bad-sha256/good-md5-bad-sha256.1/files/p.patch
358+
good-md5-bad-sha256.1: Bad hash for extra-file
359+
- ${BASEDIR}/OPAM/repo/default/packages/good-md5-bad-sha256/good-md5-bad-sha256.1/files/p.patch
353360

354361

355362
### test -f good-md5-bad-sha256.1/p.patch
356363
### rm -r good-md5-bad-sha256.1
357364
### opam source good-md5-bad-sha256 --require-checksums | '.n"' -> '"'
358365
[WARNING] Some errors extracting to ${BASEDIR}/good-md5-bad-sha256.1:
359-
Bad hash for - ${BASEDIR}/OPAM/repo/default/packages/good-md5-bad-sha256/good-md5-bad-sha256.1/files/p.patch
366+
good-md5-bad-sha256.1: Bad hash for extra-file
367+
- ${BASEDIR}/OPAM/repo/default/packages/good-md5-bad-sha256/good-md5-bad-sha256.1/files/p.patch
360368

361369

362370
### test -f good-md5-bad-sha256.1/p.patch
@@ -502,7 +510,9 @@ The following actions will be performed:
502510

503511
<><> Processing actions <><><><><><><><><><><><><><><><><><><><><><><><><><><><>
504512

505-
Sys_error("${BASEDIR}/OPAM/repo/default/packages/not-present/not-present.1/files/p.patch: No such file or directory")
513+
not-present.1: Missing extra-file for
514+
- ${BASEDIR}/OPAM/repo/default/packages/not-present/not-present.1/files/p.patch
515+
506516

507517

508518
<><> Error report <><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><>
@@ -518,7 +528,9 @@ The following actions will be performed:
518528

519529
<><> Processing actions <><><><><><><><><><><><><><><><><><><><><><><><><><><><>
520530

521-
Sys_error("${BASEDIR}/OPAM/repo/default/packages/not-present/not-present.1/files/p.patch: No such file or directory")
531+
not-present.1: Missing extra-file for
532+
- ${BASEDIR}/OPAM/repo/default/packages/not-present/not-present.1/files/p.patch
533+
522534

523535

524536
<><> Error report <><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><>
@@ -528,9 +540,11 @@ Sys_error("${BASEDIR}/OPAM/repo/default/packages/not-present/not-present.1/files
528540
- No changes have been performed
529541
# Return code 31 #
530542
### opam source not-present
531-
Fatal error:
532-
Sys_error("${BASEDIR}/OPAM/repo/default/packages/not-present/not-present.1/files/p.patch: No such file or directory")
533-
# Return code 99 #
543+
[WARNING] Some errors extracting to ${BASEDIR}/not-present.1:
544+
not-present.1: Missing extra-file for
545+
- ${BASEDIR}/OPAM/repo/default/packages/not-present/not-present.1/files/p.patch
546+
547+
534548
### test -f not-present.1/p.patch
535549
# Return code 1 #
536550
### opam clean --download-cache
@@ -554,7 +568,9 @@ The following actions will be performed:
554568

555569
<><> Processing actions <><><><><><><><><><><><><><><><><><><><><><><><><><><><>
556570

557-
Sys_error("${BASEDIR}/OPAM/repo/default/packages/escape-absolute/escape-absolute.1/files/etc/passwdd: No such file or directory")
571+
escape-absolute.1: Missing extra-file for
572+
- ${BASEDIR}/OPAM/repo/default/packages/escape-absolute/escape-absolute.1/files/etc/passwdd
573+
558574

559575

560576
<><> Error report <><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><>
@@ -570,7 +586,9 @@ The following actions will be performed:
570586

571587
<><> Processing actions <><><><><><><><><><><><><><><><><><><><><><><><><><><><>
572588

573-
Sys_error("${BASEDIR}/OPAM/repo/default/packages/escape-absolute/escape-absolute.1/files/etc/passwdd: No such file or directory")
589+
escape-absolute.1: Missing extra-file for
590+
- ${BASEDIR}/OPAM/repo/default/packages/escape-absolute/escape-absolute.1/files/etc/passwdd
591+
574592

575593

576594
<><> Error report <><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><>
@@ -580,9 +598,11 @@ Sys_error("${BASEDIR}/OPAM/repo/default/packages/escape-absolute/escape-absolute
580598
- No changes have been performed
581599
# Return code 31 #
582600
### opam source escape-absolute
583-
Fatal error:
584-
Sys_error("${BASEDIR}/OPAM/repo/default/packages/escape-absolute/escape-absolute.1/files/etc/passwdd: No such file or directory")
585-
# Return code 99 #
601+
[WARNING] Some errors extracting to ${BASEDIR}/escape-absolute.1:
602+
escape-absolute.1: Missing extra-file for
603+
- ${BASEDIR}/OPAM/repo/default/packages/escape-absolute/escape-absolute.1/files/etc/passwdd
604+
605+
586606
### test -f escape-absolute.1/p.patch
587607
# Return code 1 #
588608
### opam clean --download-cache

0 commit comments

Comments
 (0)