diff --git a/src/state/opamFileTools.ml b/src/state/opamFileTools.ml index 6ad387b2b29..df6c8e12b1a 100644 --- a/src/state/opamFileTools.ml +++ b/src/state/opamFileTools.ml @@ -1192,10 +1192,24 @@ let read_opam dir = (OpamPp.string_of_bad_format (OpamPp.Bad_format (snd err))); None | None, None -> None - | exception (OpamPp.Bad_version _bf) -> - log "opam-version unsupported on %s. Add as dummy unavailable package." + | exception (OpamPp.Bad_version (_, version) -> + log "opam-version %S unsupported on %s. Added as dummy unavailable package." version (OpamFile.to_string opam_file); - Some (OpamFile.OPAM.with_available (FBool false) OpamFile.OPAM.empty) + if OpamVersion.compare OpamVersion.current (OpamVersion.of_string version) >= 0 then begin + log "Unexpected failure: failed to parse version %S but is below the current version %S" + version (OpamVersion.to_string OpamVersion.current); + Some (OpamFile.OPAM.with_available (FBool false) OpamFile.OPAM.empty) + end else + Some + (OpamFile.OPAM.with_description + (Printf.sprintf + "This package uses opam 3.0 file format which opam 2.2 cannot read.\n\ + \n\ + In order to install or view information on this package, please upgrade your opam installation to at least version %s." + version) + (OpamFile.OPAM.with_available + (FOp (FIdent ([], OpamVariable.of_string "opam-version", None), `Ge, FString version)) + OpamFile.OPAM.empty) let read_repo_opam ~repo_name ~repo_root dir = let open OpamStd.Option.Op in