From fb84beec90283c39442ecb4de15586948ce934bb Mon Sep 17 00:00:00 2001 From: Pawel Kubik Date: Fri, 21 Aug 2015 17:19:46 +0200 Subject: [PATCH] Improved CLI connection error note. [Feature] CLI connection error note, and suggestion to launch vasum-server [Cause] Previous information was inacurate [Solution] Added proper error handling [Verification] Build, install, run cli/vsm when the server is not running Change-Id: I59a4467a25ef40e6ed650485c8ac690f955e29cc --- cli/cli-exception.hpp | 52 ++++++++++++++++++++++++++++++++++++++++++ cli/command-line-interface.cpp | 3 ++- cli/main.cpp | 5 ++++ 3 files changed, 59 insertions(+), 1 deletion(-) create mode 100644 cli/cli-exception.hpp diff --git a/cli/cli-exception.hpp b/cli/cli-exception.hpp new file mode 100644 index 0000000..982f52d --- /dev/null +++ b/cli/cli-exception.hpp @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved + * + * Contact: Pawel Kubik + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License + */ + +/** + * @file + * @author Pawel Kubik (p.kubik@samsung.com) + * @brief Exceptions for the cli + */ + + +#ifndef CLI_EXCEPTION_HPP +#define CLI_EXCEPTION_HPP + +#include "base-exception.hpp" + + +namespace vasum { +namespace cli { + + +/** + * Base class for exceptions in Vasum CLI + */ +struct CliException: public VasumException { + + CliException(const std::string& error) : VasumException(error) {} +}; + +struct IOException: public CliException { + + IOException(const std::string& error) : CliException(error) {} +}; + +} // namespace cli +} // namespace vasum + +#endif // CLI_EXCEPTION_HPP diff --git a/cli/command-line-interface.cpp b/cli/command-line-interface.cpp index 93201c3..27d7cac 100644 --- a/cli/command-line-interface.cpp +++ b/cli/command-line-interface.cpp @@ -26,6 +26,7 @@ #include "command-line-interface.hpp" #include "vasum-client.h" #include "utils/c-array.hpp" +#include "cli-exception.hpp" #include #include @@ -204,7 +205,7 @@ void CommandLineInterface::connect() string msg = vsm_get_status_message(CommandLineInterface::client); vsm_client_free(CommandLineInterface::client); CommandLineInterface::client = nullptr; - throw runtime_error(msg); + throw IOException(msg); } } diff --git a/cli/main.cpp b/cli/main.cpp index 528c4c8..537ad69 100644 --- a/cli/main.cpp +++ b/cli/main.cpp @@ -23,6 +23,7 @@ */ #include "command-line-interface.hpp" +#include "cli-exception.hpp" #include #include @@ -284,6 +285,10 @@ int connect() { try { CommandLineInterface::connect(); + } catch (const IOException& ex) { + std::cerr << ex.what() << std::endl; + std::cout << "Client connection error. Is vasum-server running?" << std::endl; + return EXIT_FAILURE; } catch (const std::runtime_error& ex) { std::cerr << ex.what() << std::endl; return EXIT_FAILURE; -- 2.7.4