src/core/config/exceptions.h

Collection of all configuration exceptions. More…

Namespaces

Name
allpix
Helper class to hold support layers for a detector model.

Classes

Name
class allpix::ConfigurationError
Base class for all configurations exceptions in the framework.
class allpix::ConfigFileUnavailableError
Notifies of a missing configuration file.
class allpix::InvalidKeyError
Indicates a problem converting the value of a configuration key to the value it should represent.
class allpix::MissingKeyError
Informs of a missing key that should have been defined.
class allpix::KeyValueParseError
Indicates an error while parsing a key / value pair.
class allpix::ConfigParseError
Indicates an error while parsing a configuration file.
class allpix::InvalidValueError
Indicates an error with the contents of value.
class allpix::InvalidCombinationError
Indicates an error with a combination of configuration keys.
class allpix::ModuleIdentifierNotFoundError
Indicates that a given ModuleIdentifier was not found in the module identifier list.
class allpix::ModuleIdentifierAlreadyAddedError
Indicates that a given ModuleIdentifier is already in the module identifier list.

Detailed Description

Collection of all configuration exceptions.

Copyright: Copyright (c) 2017-2024 CERN and the Allpix Squared 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. SPDX-License-Identifier: MIT

Source code


#ifndef ALLPIX_CONFIG_EXCEPTIONS_H
#define ALLPIX_CONFIG_EXCEPTIONS_H

#include <string>

#include "core/utils/exceptions.h"
#include "core/utils/type.h"

namespace allpix {
    class ConfigurationError : public Exception {};

    // TODO [doc] Rename to not found?
    class ConfigFileUnavailableError : public ConfigurationError {
    public:
        explicit ConfigFileUnavailableError(const std::string& file_name) {
            error_message_ = "Could not read configuration file " + file_name + " - does it exist?";
        }
    };

    // TODO [doc] this should be InvalidValueTypeError (see below)
    class InvalidKeyError : public ConfigurationError {
    public:
        InvalidKeyError(const std::string& key,
                        const std::string& section,
                        const std::string& value,
                        const std::type_info& type,
                        const std::string& reason) {
            // FIXME: file and line number are missing
            std::string section_str = "in section '" + section + "'";
            if(section.empty()) {
                section_str = "in global section";
            }

            error_message_ = "Could not convert value '" + value + "' from key '" + key + "' " + section_str + " to type " +
                             allpix::demangle(type.name());
            if(!reason.empty()) {
                error_message_ += ": " + reason;
            }
        }
    };

    class MissingKeyError : public ConfigurationError {
    public:
        MissingKeyError(const std::string& key, const std::string& section) {
            // FIXME: file and line number are missing
            std::string section_str = "in section '" + section + "'";
            if(section.empty()) {
                section_str = "in global section";
            }
            error_message_ = "Key '" + key + "' " + section_str + " does not exist";
        }
    };

    class KeyValueParseError : public ConfigurationError {
    public:
        KeyValueParseError(const std::string& key_value, const std::string& reason) {
            error_message_ = "Could not parse key / value pair '";
            error_message_ += key_value;
            error_message_ += ": " + reason;
        }
    };

    class ConfigParseError : public ConfigurationError {
    public:
        ConfigParseError(const std::string& file_name, int line_num) {
            error_message_ = "Could not parse line ";
            error_message_ += std::to_string(line_num);
            error_message_ += " in file '" + file_name + "'";
            error_message_ += ": not a valid section header, key/value pair or comment";
        }
    };

    class Configuration;
    class InvalidValueError : public ConfigurationError {
    public:
        InvalidValueError(const Configuration& config, const std::string& key, const std::string& reason = "");
    };
    class InvalidCombinationError : public ConfigurationError {
    public:
        InvalidCombinationError(const Configuration& config,
                                std::initializer_list<std::string> keys,
                                const std::string& reason = "");
    };

    class ModuleIdentifier;
    class ModuleIdentifierNotFoundError : public LogicError {
    public:
        explicit ModuleIdentifierNotFoundError(const ModuleIdentifier& identifier);
    };
    class ModuleIdentifierAlreadyAddedError : public LogicError {
    public:
        explicit ModuleIdentifierAlreadyAddedError(const ModuleIdentifier& identifier);
    };
} // namespace allpix

#endif /* ALLPIX_CONFIG_EXCEPTIONS_H */

Updated on 2024-12-13 at 08:31:37 +0000