ocaml / opam

opam is a source-based package manager. It supports multiple simultaneous compiler installations, flexible package constraints, and a Git-friendly development workflow.
https://opam.ocaml.org
Other
1.21k stars 348 forks source link

opam install fails with exitcode 5 instead of 20 when a package is unavailable #6017

Open kit-ty-kate opened 3 weeks ago

kit-ty-kate commented 3 weeks ago

Similar to https://github.com/ocaml/opam/issues/4493 Using opam 2.2.0~beta3 and https://github.com/ocaml/opam-repository/pull/26072:

$ opam install conf-libssl.1
Error:  conf-libssl = 1: unmet availability conditions: 'os != "win32" | os-distribution = "cygwinports"'
$ echo $?
5

According to the documentation, exit code 5 means:

5 Not found. You requested something (package, version, repository, etc.) that couldn't be found.

Instead, one would expect exit code 20:

20 There is no solution to the user request. This can be caused by asking to install two incompatible packages, for example.

kit-ty-kate commented 3 weeks ago

The source of the issue is located in OpamSolution.check_availability https://github.com/ocaml/opam/blob/9c7a256f60e78d1a1cc5ea90f8069a351aeb86a5/src/client/opamSolution.ml#L192 which seems to mix both concept of "unavailability because the package does not (longer) exist" and "unavailability because the package is not available on this platform"

Based on how OpamSwitchState.unavailable_reason is used everywhere else with the correct exit_reason, i strongly believe this is a bug.