Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Corryvreckan
Corryvreckan
Commits
a8eb9a9e
Commit
a8eb9a9e
authored
Dec 13, 2018
by
Simon Spannagel
Browse files
Core: update configuration exceptions
parent
f7ea1a6c
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/core/config/exceptions.cpp
View file @
a8eb9a9e
...
...
@@ -2,7 +2,7 @@
* @file
* @brief Implementation of configuration exceptions
*
* @copyright Copyright (c) 2017 CERN and the
Allpix Squared
authors.
* @copyright Copyright (c) 2017 CERN and the
Corryvreckan
authors.
* This software is distributed under the terms of the MIT License, copied verbatim in the file "LICENSE.md".
* In applying this license, CERN does not waive the privileges and immunities granted to it by virtue of its status as an
* Intergovernmental Organization or submit itself to any jurisdiction.
...
...
@@ -16,10 +16,30 @@ using namespace corryvreckan;
InvalidValueError
::
InvalidValueError
(
const
Configuration
&
config
,
const
std
::
string
&
key
,
const
std
::
string
&
reason
)
{
std
::
string
section_str
=
"in section '"
+
config
.
getName
()
+
"'"
;
if
(
config
.
getName
().
empty
())
{
section_str
=
"in
empty
section"
;
section_str
=
"in
global
section"
;
}
error_message_
=
"Value "
+
config
.
getText
(
key
)
+
" of key '"
+
key
+
"' "
+
section_str
+
" is not valid"
;
if
(
!
reason
.
empty
())
{
error_message_
+=
": "
+
reason
;
}
}
InvalidCombinationError
::
InvalidCombinationError
(
const
Configuration
&
config
,
std
::
initializer_list
<
std
::
string
>
keys
,
const
std
::
string
&
reason
)
{
std
::
string
section_str
=
"in section '"
+
config
.
getName
()
+
"'"
;
if
(
config
.
getName
().
empty
())
{
section_str
=
"in global section"
;
}
error_message_
=
"Combination of keys "
;
for
(
auto
&
key
:
keys
)
{
if
(
!
config
.
has
(
key
))
{
continue
;
}
error_message_
+=
"'"
+
key
+
"', "
;
}
error_message_
+=
section_str
+
" is not valid"
;
if
(
!
reason
.
empty
())
{
error_message_
+=
": "
+
reason
;
}
}
src/core/config/exceptions.h
View file @
a8eb9a9e
...
...
@@ -2,7 +2,7 @@
* @file
* @brief Collection of all configuration exceptions
*
* @copyright Copyright (c) 2017 CERN and the
Allpix Squared
authors.
* @copyright Copyright (c) 2017 CERN and the
Corryvreckan
authors.
* This software is distributed under the terms of the MIT License, copied verbatim in the file "LICENSE.md".
* In applying this license, CERN does not waive the privileges and immunities granted to it by virtue of its status as an
* Intergovernmental Organization or submit itself to any jurisdiction.
...
...
@@ -35,7 +35,7 @@ namespace corryvreckan {
* @param file_name Name of the configuration file
*/
explicit
ConfigFileUnavailableError
(
const
std
::
string
&
file_name
)
{
error_message_
=
"Could not read configuration file "
+
file_name
+
"
(
does it exist
s?)
"
;
error_message_
=
"Could not read configuration file "
+
file_name
+
"
-
does it exist
?
"
;
}
};
...
...
@@ -62,7 +62,7 @@ namespace corryvreckan {
// FIXME: file and line number are missing
std
::
string
section_str
=
"in section '"
+
section
+
"'"
;
if
(
section
.
empty
())
{
section_str
=
"in
empty
section"
;
section_str
=
"in
global
section"
;
}
error_message_
=
"Could not convert value '"
+
value
+
"' from key '"
+
key
+
"' "
+
section_str
+
" to type "
+
...
...
@@ -88,7 +88,7 @@ namespace corryvreckan {
// FIXME: file and line number are missing
std
::
string
section_str
=
"in section '"
+
section
+
"'"
;
if
(
section
.
empty
())
{
section_str
=
"in
empty
section"
;
section_str
=
"in
global
section"
;
}
error_message_
=
"Key '"
+
key
+
"' "
+
section_str
+
" does not exist"
;
}
...
...
@@ -102,8 +102,8 @@ namespace corryvreckan {
public:
/**
* @brief Construct an error for a invalid key value pair
* @param key_value Key value pair which
is trying to be parsed
* @param
line_num Line number where the problem occurred
* @param key_value Key value pair which
the parser tries to interpret
* @param
reason Reason for the parser to fail
*/
KeyValueParseError
(
const
std
::
string
&
key_value
,
const
std
::
string
&
reason
)
{
error_message_
=
"Could not parse key / value pair '"
;
...
...
@@ -135,7 +135,6 @@ namespace corryvreckan {
/**
* @ingroup Exceptions
* @brief Indicates an error with the contents of value
* @note Only configuration error that should be called directly from modules
*
* Should be raised if the data contains valid data for its type (otherwise an \ref InvalidKeyError should have been
* raised earlier), but the value is not in the range of allowed values.
...
...
@@ -150,6 +149,25 @@ namespace corryvreckan {
*/
InvalidValueError
(
const
Configuration
&
config
,
const
std
::
string
&
key
,
const
std
::
string
&
reason
=
""
);
};
/**
* @ingroup Exceptions
* @brief Indicates an error with a combination of configuration keys
*
* Should be raised if a disallowed combination of keys is used, such as two optional parameters which cannot be used at
* the same time because they contradict each other.
*/
class
InvalidCombinationError
:
public
ConfigurationError
{
public:
/**
* @brief Construct an error for an invalid combination of keys
* @param config Configuration object containing the problematic key combination
* @param keys List of names of the conflicting keys
* @param reason Reason why the key combination is invalid (empty if no explicit reason)
*/
InvalidCombinationError
(
const
Configuration
&
config
,
std
::
initializer_list
<
std
::
string
>
keys
,
const
std
::
string
&
reason
=
""
);
};
}
// namespace corryvreckan
#endif
/* CORRYVRECKAN_CONFIG_EXCEPTIONS_H */
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment