Skip to content

Commit c91faea

Browse files
punchaganAlizter
authored andcommitted
pkg: Show git error output when Rev_store's fetch fails
Closes #12610 Signed-off-by: Puneeth Chaganti <[email protected]>
1 parent c9ee648 commit c91faea

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

src/dune_pkg/rev_store.ml

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -725,15 +725,16 @@ let fetch_allow_failure repo ~url obj =
725725
| true -> Fiber.return `Fetched
726726
| false ->
727727
run_with_exit_code
728-
~allow_codes:(fun x -> x = 0 || x = 128)
728+
~allow_codes:(Int.equal 0)
729729
repo
730730
~display:!Dune_engine.Clflags.display
731731
[ "fetch"; "--no-write-fetch-head"; url; Object.to_hex obj ]
732732
>>| (function
733-
| Ok 128 -> `Not_found
734733
| Ok 0 ->
735734
Table.set repo.present_objects obj ();
736735
`Fetched
736+
| Error { Git_error.exit_code; output; _ } when exit_code = 128 ->
737+
`Not_found output
737738
| Error git_error -> Git_error.raise_code_error git_error
738739
| _ -> assert false))
739740
;;
@@ -742,8 +743,14 @@ let fetch repo ~url obj =
742743
fetch_allow_failure repo ~url obj
743744
>>| function
744745
| `Fetched -> ()
745-
| `Not_found ->
746-
User_error.raise [ Pp.textf "unable to fetch %S from %S" (Object.to_hex obj) url ]
746+
| `Not_found output ->
747+
User_error.raise
748+
([ Pp.textf
749+
"Dune was unable to fetch %S from %S due to the following git fetch error:"
750+
(Object.to_hex obj)
751+
url
752+
]
753+
@ List.map ~f:Pp.verbatim output)
747754
;;
748755

749756
module Debug = struct
@@ -1156,7 +1163,7 @@ let resolve_revision t (remote : Remote.t) ~revision =
11561163
let fetch_object t (remote : Remote.t) revision =
11571164
fetch_allow_failure t ~url:remote.url revision
11581165
>>= function
1159-
| `Not_found -> Fiber.return None
1166+
| `Not_found _ -> Fiber.return None
11601167
| `Fetched -> At_rev.of_rev t ~revision >>| Option.some
11611168
;;
11621169

test/blackbox-tests/test-cases/pkg/commit-hash-references.t

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,5 @@ Depend on foo from the repo
3232

3333
Which foo will we get?
3434

35-
$ dune pkg lock 2>&1 | head -1 | sed "s/$AMBIGUOUS_REF/\$AMBIGUOUS_REF/g"
35+
$ dune pkg lock 2>&1 | grep "not found" | sed "s/$AMBIGUOUS_REF/\$AMBIGUOUS_REF/g"
3636
revision "$AMBIGUOUS_REF" not found in

0 commit comments

Comments
 (0)