Permalink
Browse files

Improve the error message when using a switch which has not yet been …

…installed.

Fix #542
  • Loading branch information...
1 parent a66421f commit 66048a15e86698c5f5bda3946860ed7af3be54f8 @samoht samoht committed Mar 19, 2013
Showing with 24 additions and 13 deletions.
  1. +1 −1 Makefile
  2. +15 −12 src/client/opamState.ml
  3. +5 −0 src/core/opamSwitch.ml
  4. +3 −0 src/core/opamSwitch.mli
View
@@ -1,6 +1,6 @@
-include Makefile.config
-LOCAL_OCPBUILD=./ocp-build/ocp-build
+LOCAL_OCPBUILD=./ocp-build/ocp-build -no-use-ocamlfind
OCPBUILD ?= $(LOCAL_OCPBUILD)
SRC_EXT=src_ext
TARGETS = opam opam-mk-repo
View
@@ -610,18 +610,21 @@ let load_state ?(save_cache=true) call_site =
log "%S does not contain the compiler name associated to the switch %s"
(OpamFilename.to_string (OpamPath.aliases root))
(OpamSwitch.to_string switch);
- if OpamSwitch.Map.cardinal aliases > 0 then (
- let new_switch, new_compiler = OpamSwitch.Map.choose aliases in
- OpamGlobals.error "The current switch (%s) is an unknown compiler switch. Switching back to %s ..."
- (OpamSwitch.to_string switch)
- (OpamSwitch.to_string new_switch);
- let config = OpamFile.Config.with_switch config new_switch in
- OpamFile.Config.write config_p config;
- new_switch, new_compiler;
- ) else
- OpamGlobals.error_and_exit
- "The current switch (%s) is an unknown compiler switch."
- (OpamSwitch.to_string switch) in
+ match !OpamGlobals.switch with
+ | Some s -> OpamSwitch.not_installed (OpamSwitch.of_string s)
+ | None ->
+ if OpamSwitch.Map.cardinal aliases > 0 then (
+ let new_switch, new_compiler = OpamSwitch.Map.choose aliases in
+ OpamGlobals.error "The current switch (%s) is an unknown compiler switch. Switching back to %s ..."
+ (OpamSwitch.to_string switch)
+ (OpamSwitch.to_string new_switch);
+ let config = OpamFile.Config.with_switch config new_switch in
+ OpamFile.Config.write config_p config;
+ new_switch, new_compiler;
+ ) else
+ OpamGlobals.error_and_exit
+ "The current switch (%s) is an unknown compiler switch."
+ (OpamSwitch.to_string switch) in
let compiler_version =
let comp_f = OpamPath.compiler root compiler in
View
@@ -16,3 +16,8 @@
include OpamMisc.Base
let default = of_string OpamGlobals.system
+
+let not_installed s =
+ OpamGlobals.error_and_exit
+ "The compiler switch %s is not installed."
+ (to_string s)
View
@@ -19,3 +19,6 @@ include OpamMisc.ABSTRACT
(** Default switch *)
val default: t
+
+(** Display a nice error message when a switch is not installed. *)
+val not_installed: t -> 'a

0 comments on commit 66048a1

Please sign in to comment.