Browse files

Be more robust in case some rubish appear in ~/.opam/config:switch. I…

…f this contains an unknown switch (it should normally not happen ...) then switch back to an existing compiler switch.
  • Loading branch information...
1 parent 1ef4805 commit 33a5794e75d97247fb71b75c011937334b6eaa7a @samoht samoht committed Nov 15, 2012
Showing with 15 additions and 4 deletions.
  1. +15 −4 src/client/opamState.ml
View
19 src/client/opamState.ml
@@ -276,14 +276,25 @@ let load_state () =
| None -> OpamFile.Config.switch config
| Some a -> OpamSwitch.of_string a in
let aliases = OpamFile.Aliases.safe_read (OpamPath.aliases root) in
- let compiler =
- try OpamSwitch.Map.find switch aliases
+ let switch, compiler =
+ try switch, OpamSwitch.Map.find switch aliases
with Not_found ->
- OpamGlobals.error "%s is an unknown compiler switch" (OpamSwitch.to_string switch);
log "%S does not contain the compiler name associated to the switch %s"
(OpamFilename.to_string (OpamPath.aliases root))
(OpamSwitch.to_string switch);
- OpamGlobals.exit 2 in
+ 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 = OpamFile.Comp.read (OpamPath.compiler root compiler) in
OpamFile.Comp.version comp in

0 comments on commit 33a5794

Please sign in to comment.