Leosac  0.8.0
Open Source Access Control
configexception.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2014-2016 Leosac
3 
4  This file is part of Leosac.
5 
6  Leosac is free software: you can redistribute it and/or modify
7  it under the terms of the GNU Affero General Public License as published by
8  the Free Software Foundation, either version 3 of the License, or
9  (at your option) any later version.
10 
11  Leosac is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU Affero General Public License for more details.
15 
16  You should have received a copy of the GNU Affero General Public License
17  along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19 
20 #pragma once
21 
22 #include "leosacexception.hpp"
23 #include "tools/Colorize.hpp"
24 #include <string>
25 
26 namespace Leosac
27 {
28 namespace Ex
29 {
33 class Config : public LEOSACException
34 {
35  public:
46  Config(const std::string &config_target, const std::string &config_entry,
47  bool not_found)
48  : LEOSACException(build_message(config_target, config_entry, not_found))
49  {
50  }
51 
56  Config(const std::string &filename)
57  : LEOSACException(build_message(filename))
58  {
59  }
60 
61  private:
62  static std::string build_message(const std::string &config_target,
63  const std::string &config_entry, bool not_found)
64  {
65  using namespace Colorize;
66  if (not_found)
67  {
68  return "Missing configuration entry for " + green(config_target) + ": " +
69  underline(red(config_entry));
70  }
71  else
72  {
73  return "Invalid configuration entry for " + green(config_target) + ": " +
74  underline(red(config_entry));
75  }
76  }
77 
78  static std::string build_message(const std::string &filename)
79  {
80  using namespace Colorize;
81  return "Failed to parse configuration file " + underline(green(filename));
82  }
83 };
84 }
85 }
86 
88 {
89  public:
90  ConfigException(const std::string &file, const std::string &message)
91  : LEOSACException("Configuration error in file {" + file + "}: " + message)
92  {
93  }
94  virtual ~ConfigException()
95  {
96  }
97 };
ConfigException::~ConfigException
virtual ~ConfigException()
Definition: configexception.hpp:94
Colorize.hpp
Leosac::Colorize::underline
std::string underline(const T &in)
Definition: Colorize.hpp:64
Leosac
This is the header file for a generated source file, GitSHA1.cpp.
Definition: APIStatusCode.hpp:22
leosacexception.hpp
Exception class for LEOSAC Project related errors.
ConfigException
Definition: configexception.hpp:87
LEOSACException
A base class for Leosac specific exception.
Definition: leosacexception.hpp:40
ConfigException::ConfigException
ConfigException(const std::string &file, const std::string &message)
Definition: configexception.hpp:90
Leosac::Ex::Config::build_message
static std::string build_message(const std::string &config_target, const std::string &config_entry, bool not_found)
Definition: configexception.hpp:62
Leosac::Colorize::green
std::string green(const T &in)
Definition: Colorize.hpp:82
Leosac::Colorize::red
std::string red(const T &in)
Definition: Colorize.hpp:70
Leosac::Ex::Config::Config
Config(const std::string &config_target, const std::string &config_entry, bool not_found)
Construct a config exception for when we failed to load a property.
Definition: configexception.hpp:46
Leosac::Ex::Config
An exception related to configuration.
Definition: configexception.hpp:33
Leosac::Ex::Config::build_message
static std::string build_message(const std::string &filename)
Definition: configexception.hpp:78
Leosac::Ex::Config::Config
Config(const std::string &filename)
Create a config exception when we failed to parse a configuration file.
Definition: configexception.hpp:56