Commit b45048d4 authored by Francis Dupont's avatar Francis Dupont
Browse files

[master] Merged trac3697 (cryptic error on invalid config)

parents 3b21f023 5e490e86
......@@ -65,6 +65,17 @@ void configure(const std::string& file_name) {
isc_throw(isc::BadValue, "no configuration found");
}
// Let's do sanity check before we call json->get() which
// works only for map.
if (json->getType() != isc::data::Element::map) {
isc_throw(isc::BadValue, "Configuration file is expected to be "
"a map, i.e., start with { and end with } and contain "
"at least an entry called 'Dhcp4' that itself is a map. "
<< file_name
<< " is a valid JSON, but its top element is not a map."
" Did you forget to add { } around your configuration?");
}
// If there's no logging element, we'll just pass NULL pointer,
// which will be handled by configureLogger().
Daemon::configureLogger(json->get("Logging"),
......
......@@ -69,6 +69,17 @@ void configure(const std::string& file_name) {
isc_throw(isc::BadValue, "no configuration found");
}
// Let's do sanity check before we call json->get() which
// works only for map.
if (json->getType() != isc::data::Element::map) {
isc_throw(isc::BadValue, "Configuration file is expected to be "
"a map, i.e., start with { and end with } and contain "
"at least an entry called 'Dhcp6' that itself is a map. "
<< file_name
<< " is a valid JSON, but its top element is not a map."
" Did you forget to add { } around your configuration?");
}
// Let's configure logging before applying the configuration,
// so we can log things during configuration process.
// If there's no logging element, we'll just pass NULL pointer,
......
......@@ -135,57 +135,57 @@ Element::setValue(const std::map<std::string, ConstElementPtr>&) {
ConstElementPtr
Element::get(const int) const {
isc_throw(TypeError, "get(int) called on a non-list Element");
throwTypeError("get(int) called on a non-list Element");
}
void
Element::set(const size_t, ConstElementPtr) {
isc_throw(TypeError, "set(int, element) called on a non-list Element");
throwTypeError("set(int, element) called on a non-list Element");
}
void
Element::add(ConstElementPtr) {
isc_throw(TypeError, "add() called on a non-list Element");
throwTypeError("add() called on a non-list Element");
}
void
Element::remove(const int) {
isc_throw(TypeError, "remove(int) called on a non-list Element");
throwTypeError("remove(int) called on a non-list Element");
}
size_t
Element::size() const {
isc_throw(TypeError, "size() called on a non-list Element");
throwTypeError("size() called on a non-list Element");
}
bool
Element::empty() const {
isc_throw(TypeError, "empty() called on a non-list Element");
throwTypeError("empty() called on a non-list Element");
}
ConstElementPtr
Element::get(const std::string&) const {
isc_throw(TypeError, "get(string) called on a non-map Element");
throwTypeError("get(string) called on a non-map Element");
}
void
Element::set(const std::string&, ConstElementPtr) {
isc_throw(TypeError, "set(name, element) called on a non-map Element");
throwTypeError("set(name, element) called on a non-map Element");
}
void
Element::remove(const std::string&) {
isc_throw(TypeError, "remove(string) called on a non-map Element");
throwTypeError("remove(string) called on a non-map Element");
}
bool
Element::contains(const std::string&) const {
isc_throw(TypeError, "contains(string) called on a non-map Element");
throwTypeError("contains(string) called on a non-map Element");
}
ConstElementPtr
Element::find(const std::string&) const {
isc_throw(TypeError, "find(string) called on a non-map Element");
throwTypeError("find(string) called on a non-map Element");
}
bool
......
// Copyright (C) 2010, 2014 Internet Systems Consortium, Inc. ("ISC")
// Copyright (C) 2010, 2014, 2015 Internet Systems Consortium, Inc. ("ISC")
//
// Permission to use, copy, modify, and/or distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
......@@ -186,6 +186,19 @@ public:
std::string toWire() const;
void toWire(std::ostream& out) const;
/// \brief Add the position to a TypeError message
/// should be used in place of isc_throw(TypeError, error)
#define throwTypeError(error) \
{ \
std::string msg_ = error; \
if ((position_.file_ != "") || \
(position_.line_ != 0) || \
(position_.pos_ != 0)) { \
msg_ += " in " + position_.str(); \
} \
isc_throw(TypeError, msg_); \
}
/// \name pure virtuals, every derived class must implement these
/// \return true if the other ElementPtr has the same type and value
......@@ -204,20 +217,20 @@ public:
/// getValue() below
//@{
virtual int64_t intValue() const
{ isc_throw(TypeError, "intValue() called on non-integer Element"); };
{ throwTypeError("intValue() called on non-integer Element"); };
virtual double doubleValue() const
{ isc_throw(TypeError, "doubleValue() called on non-double Element"); };
{ throwTypeError("doubleValue() called on non-double Element"); };
virtual bool boolValue() const
{ isc_throw(TypeError, "boolValue() called on non-Bool Element"); };
{ throwTypeError("boolValue() called on non-Bool Element"); };
virtual std::string stringValue() const
{ isc_throw(TypeError, "stringValue() called on non-string Element"); };
{ throwTypeError("stringValue() called on non-string Element"); };
virtual const std::vector<ConstElementPtr>& listValue() const {
// replace with real exception or empty vector?
isc_throw(TypeError, "listValue() called on non-list Element");
throwTypeError("listValue() called on non-list Element");
};
virtual const std::map<std::string, ConstElementPtr>& mapValue() const {
// replace with real exception or empty map?
isc_throw(TypeError, "mapValue() called on non-map Element");
throwTypeError("mapValue() called on non-map Element");
};
//@}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment