"""Exceptions for module_management package."""
# This file is part of FAST-OAD : A framework for rapid Overall Aircraft Design
# Copyright (C) 2022 ONERA & ISAE-SUPAERO
# FAST is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
from collections.abc import Sequence
from fastoad.exceptions import FastError
[docs]
class FastBundleLoaderDuplicateFactoryError(FastError):
"""
Raised when trying to register a factory with an already used name.
"""
def __init__(self, factory_name: str):
"""
:param factory_name:
"""
super().__init__(f'Name "{factory_name}" is already used.')
self.factory_name = factory_name
[docs]
class FastBundleLoaderUnknownFactoryNameError(FastError):
"""
Raised when trying to instantiate a component from an unknown factory.
"""
def __init__(self, factory_name: str):
"""
:param factory_name:
"""
super().__init__(f'"{factory_name}" is not registered.')
self.factory_name = factory_name
[docs]
class FastBundleLoaderUnavailableFactoryError(FastError):
"""
Raised when trying to instantiate a component from a known factory but which is unavailable for
instantiation. Can be used for a component that requires a package which is not installed by
default (either because it is an extra dependency or a private package) or for a component that
needs credentials to access private database.
"""
[docs]
class FastBadSystemOptionError(FastError):
"""
Raised when some option name is not conform to OpenMDAO system definition.
"""
def __init__(self, identifier, option_names):
"""
:param identifier: system identifier
:param option_names: incorrect option names
"""
super().__init__(
f"OpenMDAO system {identifier} does not accept following option(s): {option_names}"
)
self.identifier = identifier
self.option_names = option_names
[docs]
class FastIncompatibleServiceClassError(FastError):
"""
Raised when trying to register as service a class that does not implement
the specified interface.
"""
def __init__(self, registered_class: type, service_id: str, base_class: type):
"""
:param registered_class:
:param service_id:
:param base_class: the unmatched interface
"""
super().__init__(
f'Trying to register {registered_class!s} as service "{service_id}" but it does not '
f"inherit from {base_class!s}"
)
self.registered_class = registered_class
self.service_id = service_id
self.base_class = base_class
[docs]
class FastNoSubmodelFoundError(FastError):
"""
Raised when a submodel is required, but none has been declared.
"""
def __init__(self, service_id: str):
"""
:param service_id:
"""
super().__init__(f'No submodel found for requirement "{service_id}"')
self.service_id = service_id
[docs]
class FastTooManySubmodelsError(FastError):
"""
Raised when several candidates are declared for a required submodel, but
none has been selected.
"""
def __init__(self, service_id: str, candidates: Sequence[str]):
"""
:param service_id:
:param candidates:
"""
super().__init__(
f'Submodel requirement "{service_id}" needs a choice among following '
f"candidates: {candidates}"
)
self.service_id = service_id
self.candidates = candidates
[docs]
class FastUnknownSubmodelError(FastError):
"""
Raised when a submodel identifier is unknown for given required service.
"""
def __init__(self, service_id: str, submodel_id: str, submodel_ids: list[str]):
"""
:param service_id:
:param submodel_id:
:param submodel_ids:
"""
msg = f'"{submodel_id}" is not a submodel identifier for requirement "{service_id}"'
msg += f"\nValid identifiers are {submodel_ids}"
super().__init__(msg)
self.service_id = service_id
self.submodel_id = submodel_id
[docs]
class FastNoDistPluginError(FastError):
"""Raised when no installed package with FAST-OAD plugin is available."""
def __init__(self):
super().__init__("This feature needs plugins, but no plugin available.")
[docs]
class FastUnknownDistPluginError(FastError):
"""Raised when a distribution name is not found among distribution with FAST-OAD plugins."""
def __init__(self, dist_name):
self.dist_name = dist_name
super().__init__(
f'No installed package with FAST-OAD plugin found with name "{dist_name}".'
)
[docs]
class FastSeveralDistPluginsError(FastError):
"""
Raised when no distribution name has been specified but several distribution
with FAST-OAD plugins are available.
"""
def __init__(self):
super().__init__(
"Several installed packages with FAST-OAD plugins are available. One must be specified."
)
[docs]
class FastNoAvailableConfigurationFileError(FastError):
"""Raised when a configuration file is asked, but none is available in plugins."""
def __init__(self):
super().__init__("No configuration file provided with currently installed plugins.")
[docs]
class FastUnknownConfigurationFileError(FastError):
"""Raised when a configuration file is not found for named distribution."""
def __init__(self, configuration_file, dist_name):
self.configuration_file = configuration_file
self.dist_name = dist_name
super().__init__(
f'Configuration file "{configuration_file}" not provided with '
f'installed package "{dist_name}".'
)
[docs]
class FastSeveralConfigurationFilesError(FastError):
"""
Raised when no configuration file has been specified but several configuration files are
provided with the distribution."""
def __init__(self, dist_name):
self.dist_name = dist_name
super().__init__(
f'Installed package "{dist_name}" provides several configuration files. '
"One must be specified."
)
[docs]
class FastNoAvailableSourceDataFileError(FastError):
"""Raised when a source data file is requested, but none is available in plugins."""
def __init__(self):
super().__init__("No source data file provided with currently installed plugins.")
[docs]
class FastUnknownSourceDataFileError(FastError):
"""Raised when a source data file is not found for named distribution."""
def __init__(self, source_data_file, dist_name):
self.source_data_file = source_data_file
self.dist_name = dist_name
super().__init__(
f'Source data file "{source_data_file}" not provided with '
f'installed package "{dist_name}".'
)
[docs]
class FastSeveralSourceDataFilesError(FastError):
"""
Raised when no source data file has been specified but several source data files are
provided with the distribution."""
def __init__(self, dist_name):
self.dist_name = dist_name
super().__init__(
f'Installed package "{dist_name}" provides several source data files. '
"One must be specified."
)