Config Exceptions¶
Configuration failures surface through a dedicated hierarchy rooted at KstlibError. Importing from
kstlib.config.exceptions keeps the error handling consistent across loaders, exporters, and the CLI.
Exception Hierarchy¶
KstlibError
└── ConfigError
├── ConfigFileNotFoundError # Config file not found
├── ConfigFormatError # Invalid YAML/JSON format
├── ConfigCircularIncludeError # Recursive include detected
├── ConfigIncludeDepthError # Include depth exceeded (max 10)
└── ConfigNotLoadedError # Config not initialized
Quick overview¶
KstlibErrorgroups every library-specific exception so callers can guard large sections of code with a singleexcept.ConfigErrornarrows that scope to configuration-specific faults; downstream modules inherit from it when they depend on config state.ConfigFileNotFoundErrorextendsFileNotFoundErrorto include the missing path in the message.ConfigFormatErrorcaptures parsing issues (unsupported extension, invalid YAML/JSON, strict mode violations).ConfigCircularIncludeErrorprevents recursiveincludedirectives.ConfigIncludeDepthErrorprevents deeply nested includes (max depth: 10) to protect against resource exhaustion attacks or misconfiguration.ConfigNotLoadedErroris raised by helpers such asrequire_config()when the global configuration has not been initialised yet.
Usage patterns¶
Guarding config loads¶
from kstlib.config import load_config
from kstlib.config.exceptions import ConfigFileNotFoundError, ConfigFormatError
try:
config = load_config("kstlib.conf.yml")
except ConfigFileNotFoundError:
raise SystemExit("Config missing; run kstlib config init")
except ConfigFormatError as error:
raise SystemExit(f"Config invalid: {error}")
Ensuring configuration is present¶
from kstlib.config import require_config
from kstlib.config.exceptions import ConfigNotLoadedError
try:
config = require_config()
except ConfigNotLoadedError:
config = load_default_profile()
Module reference¶
Exception hierarchy for kstlib.
All kstlib exceptions inherit from KstlibError, allowing users to catch all kstlib-specific errors with a single except clause.
Example
- try:
config = load_config()
- except KstlibError as e:
# Catch any kstlib error print(f”Error: {e}”)
- exception kstlib.config.exceptions.ConfigCircularIncludeError[source]
Bases:
ConfigError,ValueErrorCircular include detected in configuration files.
Raised when an include chain creates a cycle (A includes B, B includes A).
- exception kstlib.config.exceptions.ConfigError[source]
Bases:
KstlibErrorBase exception for configuration-related errors.
All config module exceptions inherit from this class.
- exception kstlib.config.exceptions.ConfigFileNotFoundError[source]
Bases:
ConfigError,FileNotFoundErrorConfiguration file not found at specified location.
Raised when attempting to load a config file that doesn’t exist.
- exception kstlib.config.exceptions.ConfigFormatError[source]
Bases:
ConfigError,ValueErrorInvalid configuration format or unsupported file type.
Raised when: - File extension is not supported (.xml, etc.) - Format mismatch in strict mode (YAML including JSON) - Invalid content that cannot be parsed
- exception kstlib.config.exceptions.ConfigIncludeDepthError[source]
Bases:
ConfigError,ValueErrorInclude depth limit exceeded.
Raised when config includes are nested too deeply, which may indicate a misconfiguration or an attempt to exhaust resources.
- exception kstlib.config.exceptions.ConfigNotLoadedError[source]
Bases:
ConfigError,RuntimeErrorConfiguration not loaded yet.
Raised by require_config() when attempting to access config before it has been loaded via get_config() or load_config().
- exception kstlib.config.exceptions.ConfigSopsError[source]
Bases:
ConfigErrorSOPS decryption failed for a configuration file.
Raised when SOPS binary fails to decrypt a .sops.* file.
- exception kstlib.config.exceptions.ConfigSopsNotAvailableError[source]
Bases:
ConfigSopsErrorSOPS binary not installed or not found in PATH.
Raised when attempting to decrypt a .sops.* file but the SOPS binary is not available. Install from https://github.com/getsops/sops