Permalink
Browse files

Improve error reporting on 'opam init'.

* better error message in case the repository address is invalid
* better error message in case the compiler name is invalide

This should improve #357
  • Loading branch information...
1 parent af7b0f9 commit 020c387788413edd8da52edf5a7bfe45c2054e08 @samoht samoht committed Jan 7, 2013
Showing with 27 additions and 13 deletions.
  1. +9 −2 src/client/opamState.ml
  2. +3 −0 src/client/opamState.mli
  3. +2 −4 src/client/opamSwitchCommand.ml
  4. +13 −7 src/repositories/opamHTTP.ml
View
@@ -55,6 +55,11 @@ let unavailable_package name version =
(OpamPackage.Version.to_string v)
(OpamPackage.Name.to_string name)
+let unknown_compiler compiler =
+ OpamGlobals.error_and_exit
+ "%S is not a valid compiler."
+ (OpamCompiler.to_string compiler)
+
let check f =
let root = OpamPath.default () in
let with_switch_lock a f =
@@ -369,8 +374,10 @@ let load_state () =
(OpamSwitch.to_string switch) in
let compiler_version =
- let comp = OpamFile.Comp.read (OpamPath.compiler root compiler) in
- OpamFile.Comp.version comp in
+ let comp_f = OpamPath.compiler root compiler in
+ if not (OpamFilename.exists comp_f) then
+ unknown_compiler compiler;
+ OpamFile.Comp.version (OpamFile.Comp.read comp_f) in
let opams =
OpamPackage.Set.fold (fun nv map ->
try
View
@@ -82,6 +82,9 @@ val unknown_package: name -> version option -> 'a
is not available for the current OS or compiler. *)
val unavailable_package: name -> version option -> 'a
+(** Unknown compiler. *)
+val unknown_compiler: compiler -> 'a
+
(** {2 Environment} *)
(** Get the current environment *)
@@ -182,10 +182,8 @@ let switch ~quiet switch =
let comp_dir = OpamPath.Switch.root t.root switch in
let compiler = OpamCompiler.of_string (OpamSwitch.to_string switch) in
let comp_f = OpamPath.compiler t.root compiler in
- if not (OpamFilename.exists_dir comp_dir) && not (OpamFilename.exists comp_f) then (
- OpamGlobals.error "The compiler's description for %s does not exist.\n" (OpamSwitch.to_string switch);
- OpamGlobals.exit 1;
- );
+ if not (OpamFilename.exists_dir comp_dir) && not (OpamFilename.exists comp_f) then
+ OpamState.unknown_compiler compiler;
if not (OpamSwitch.Map.mem switch t.aliases) then
install quiet switch compiler
else
@@ -97,15 +97,21 @@ let is_up_to_date state local_file =
module B = struct
let init ~address =
- let state = make_state ~download_index:true address in
- (* Download index.tar.gz *)
try
- let file = OpamFilename.download ~overwrite:true state.remote_index_archive state.local_dir in
- OpamFilename.extract_in file state.local_dir
+ (* Download urls.txt *)
+ let state = make_state ~download_index:true address in
+ try
+ (* Download index.tar.gz *)
+ let file = OpamFilename.download ~overwrite:true state.remote_index_archive state.local_dir in
+ OpamFilename.extract_in file state.local_dir
+ with _ ->
+ OpamGlobals.msg
+ "Cannot find index.tar.gz on the OPAM repository. \
+ Initialisation might take some time.\n"
with _ ->
- OpamGlobals.msg
- "Cannot find index.tar.gz on the OPAM repository. \
- Initialisation might take some time.\n"
+ OpamGlobals.error_and_exit
+ "Error: %s is unavailable."
+ (OpamFilename.Dir.to_string address)
let curl ~remote_file ~local_file =
log "dowloading %s" (OpamFilename.to_string remote_file);

0 comments on commit 020c387

Please sign in to comment.