Line data Source code
1 : /**
2 : * Copyright Soramitsu Co., Ltd. 2017 All Rights Reserved.
3 : * http://soramitsu.co.jp
4 : *
5 : * Licensed under the Apache License, Version 2.0 (the "License");
6 : * you may not use this file except in compliance with the License.
7 : * You may obtain a copy of the License at
8 : *
9 : * http://www.apache.org/licenses/LICENSE-2.0
10 : *
11 : * Unless required by applicable law or agreed to in writing, software
12 : * distributed under the License is distributed on an "AS IS" BASIS,
13 : * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 : * See the License for the specific language governing permissions and
15 : * limitations under the License.
16 : */
17 :
18 : #ifndef IROHA_CLI_ASSERT_CONFIG_HPP
19 : #define IROHA_CLI_ASSERT_CONFIG_HPP
20 :
21 : #include <stdexcept>
22 : #include <string>
23 :
24 : namespace assert_config {
25 : /**
26 : * error message helpers that are used in json validation.
27 : */
28 : inline std::string no_member_error(std::string const &member) {
29 80 : return "No member '" + member + "'";
30 0 : }
31 :
32 : inline std::string type_error(std::string const &value,
33 : std::string const &type) {
34 80 : return "'" + value + "' is not " + type;
35 0 : }
36 :
37 : inline std::string parse_error(std::string const &path) {
38 : return "Parse error. JSON file path: " + path + "'";
39 : }
40 :
41 : /**
42 : * shuts down process when some error occurs.
43 : * @param error - error message
44 : */
45 : inline void fatal_error(std::string const &error) {
46 0 : throw std::runtime_error(error);
47 0 : }
48 :
49 : /**
50 : * shuts down process if a given condition is false.
51 : * @param condition
52 : * @param error - error message
53 : */
54 : inline void assert_fatal(bool condition, std::string const &error) {
55 170 : if (!condition) {
56 0 : fatal_error(error);
57 0 : }
58 170 : }
59 : } // namespace assert_config
60 :
61 : #endif // IROHA_CLI_ASSERT_CONFIG_HPP
|