Client: do not fail when the protocol is unknown...

This commit is contained in:
Grégoire Henry 2017-03-13 17:40:51 +01:00 committed by Benjamin Canou
parent 7ba73a5955
commit 2d828060d5

View File

@ -9,7 +9,7 @@
(* Tezos Command line interface - Main Program *) (* Tezos Command line interface - Main Program *)
open Lwt open Lwt.Infix
let cctxt = let cctxt =
let startup = let startup =
@ -36,61 +36,59 @@ let cctxt =
let main () = let main () =
Random.self_init () ; Random.self_init () ;
Sodium.Random.stir () ; Sodium.Random.stir () ;
catch Lwt.catch begin fun () ->
(fun () -> Client_config.preparse_args Sys.argv cctxt >>= fun block ->
Client_config.preparse_args Sys.argv cctxt >>= fun block -> Lwt.catch begin fun () ->
Lwt.catch Client_node_rpcs.Blocks.protocol cctxt block >>= fun version ->
(fun () -> Lwt.return (Some version, Client_commands.commands_for_version version)
Client_node_rpcs.Blocks.protocol cctxt block) end begin fun exn ->
(fun exn -> cctxt.warning
cctxt.warning "Failed to acquire the protocol version from the node: %s."
"Error trying to acquire the protocol version from the node: %s." (match exn with
(match exn with | Failure msg -> msg
| Failure msg -> msg | exn -> Printexc.to_string exn) >>= fun () ->
| exn -> Printexc.to_string exn) >>= fun () -> Lwt.return (None, [])
cctxt.warning end >>= fun (version, commands_for_version) ->
"Using the default protocol version." >>= fun () -> let commands =
Lwt.return Client_alpha.Client_proto_main.protocol) Client_generic_rpcs.commands @
>>= fun version -> Client_network.commands () @
let commands = Client_keys.commands () @
Client_generic_rpcs.commands @ Client_protocols.commands () @
Client_network.commands () @ Client_helpers.commands () @
Client_keys.commands () @ commands_for_version in
Client_protocols.commands () @ Client_config.parse_args ?version
Client_helpers.commands () @ (Cli_entries.usage ~commands)
Client_commands.commands_for_version version in (Cli_entries.inline_dispatch commands)
Client_config.parse_args ~version Sys.argv cctxt >>= fun command ->
(Cli_entries.usage ~commands) command cctxt >>= fun () ->
(Cli_entries.inline_dispatch commands) Lwt.return 0
Sys.argv cctxt >>= fun command -> end begin function
command cctxt >>= fun () -> | Arg.Help help ->
Lwt.return 0) Format.printf "%s%!" help ;
(function Lwt.return 0
| Arg.Help help -> | Arg.Bad help ->
Format.printf "%s%!" help ; Format.eprintf "%s%!" help ;
Lwt.return 0 Lwt.return 1
| Arg.Bad help -> | Cli_entries.Command_not_found ->
Format.eprintf "%s%!" help ; Format.eprintf "Unkonwn command, try `-help`.\n%!" ;
Lwt.return 1 Lwt.return 1
| Cli_entries.Command_not_found -> | Client_commands.Version_not_found ->
Format.eprintf "Unkonwn command, try `-help`.\n%!" ; Format.eprintf "Unkonwn protocol version, try `list versions`.\n%!" ;
Lwt.return 1 Lwt.return 1
| Client_commands.Version_not_found -> | Cli_entries.Bad_argument (idx, _n, v) ->
Format.eprintf "Unkonwn protocol version, try `list versions`.\n%!" ; Format.eprintf "There's a problem with argument %d, %s.\n%!" idx v ;
Lwt.return 1 Lwt.return 1
| Cli_entries.Bad_argument (idx, _n, v) -> | Cli_entries.Command_failed message ->
Format.eprintf "There's a problem with argument %d, %s.\n%!" idx v ; Format.eprintf "Command failed, %s.\n%!" message ;
Lwt.return 1 Lwt.return 1
| Cli_entries.Command_failed message -> | Failure message ->
Format.eprintf "Command failed, %s.\n%!" message ; Format.eprintf "Fatal error: %s\n%!" message ;
Lwt.return 1 Lwt.return 1
| Failure message -> | exn ->
Format.eprintf "Fatal error: %s\n%!" message ; Format.printf "Fatal internal error: %s\n%!"
Lwt.return 1 (Printexc.to_string exn) ;
| exn -> Lwt.return 1
Format.printf "Fatal internal error: %s\n%!" end
(Printexc.to_string exn) ;
Lwt.return 1)
(* Where all the user friendliness starts *) (* Where all the user friendliness starts *)
let () = Pervasives.exit (Lwt_main.run (main ())) let () = Pervasives.exit (Lwt_main.run (main ()))