exceptions
Custom exceptions for sparkwheel with source location tracking and helpful error messages.
BaseError
Bases: Exception
Base exception for sparkwheel with rich error context.
Attributes:
| Name | Type | Description |
|---|---|---|
message |
The error message |
|
source_location |
Optional location in config file where error occurred |
|
suggestion |
Optional helpful suggestion for fixing the error |
Source code in src/sparkwheel/utils/exceptions.py
_format_message()
Format error message with source location and suggestions.
Critical info (file:line) is on the first line for Rich compatibility, since Rich's traceback only shows the first line of exception messages.
Source code in src/sparkwheel/utils/exceptions.py
_get_config_snippet()
Extract and format a code snippet from the config file.
Source code in src/sparkwheel/utils/exceptions.py
CircularReferenceError
ConfigKeyError
Bases: BaseError
Raised when a config key is not found.
Supports smart suggestions and available keys display.
Source code in src/sparkwheel/utils/exceptions.py
__init__(message, source_location=None, suggestion=None, missing_key=None, available_keys=None, config_context=None)
Initialize ConfigKeyError with enhanced context.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
message
|
str
|
Error message |
required |
source_location
|
Location | None
|
Location where error occurred |
None
|
suggestion
|
str | None
|
Manual suggestion (optional) |
None
|
missing_key
|
str | None
|
The key that wasn't found |
None
|
available_keys
|
list[str] | None
|
List of available keys for suggestions |
None
|
config_context
|
dict[str, Any] | None
|
The config dict where the key wasn't found (for displaying available keys) |
None
|
Source code in src/sparkwheel/utils/exceptions.py
_generate_suggestion()
Generate smart suggestion with typo detection and available keys.
Source code in src/sparkwheel/utils/exceptions.py
ConfigMergeError
Bases: BaseError
Raised when configuration merge operation fails.
This is typically raised when using operators (= or ~) incorrectly: - Using ~ on a non-existent key - Using ~ with invalid value (must be null, empty, or list) - Type mismatch during merge (e.g., trying to merge dict into list)
Source code in src/sparkwheel/utils/exceptions.py
EvaluationError
FrozenConfigError
Bases: BaseError
Raised when attempting to modify a frozen config.
Attributes:
| Name | Type | Description |
|---|---|---|
message |
Error description |
|
field_path |
Path that was attempted to modify |
Source code in src/sparkwheel/utils/exceptions.py
InstantiationError
Location
dataclass
Tracks the location of a config item in source files.
Attributes:
| Name | Type | Description |
|---|---|---|
filepath |
str
|
Path to the source file |
line |
int
|
Line number in the file (must be >= 1) |
column |
int
|
Column number (0 if not available) |
id |
str
|
Config path ID (e.g., "model::lr") |
Source code in src/sparkwheel/utils/exceptions.py
TargetNotFoundError
build_missing_key_error(key, available_keys, source_location=None, *, max_suggestions=3, max_available_keys=10, parent_key=None)
Build a ConfigMergeError for a missing key with helpful suggestions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str
|
The key that wasn't found |
required |
available_keys
|
list[str]
|
List of available keys to compare against |
required |
source_location
|
Location | None
|
Optional location where error occurred |
None
|
max_suggestions
|
int
|
Maximum number of suggestions to show (default: 3) |
3
|
max_available_keys
|
int
|
Maximum number of available keys to show (default: 10) |
10
|
parent_key
|
str | None
|
Optional parent key for nested deletions (e.g., "model" when deleting "model.lr") |
None
|
Returns:
| Type | Description |
|---|---|
ConfigMergeError
|
ConfigMergeError with helpful suggestions |
Examples:
>>> error = build_missing_key_error("paramters", ["parameters", "param_groups"])
>>> print(error._original_message)
Cannot delete key 'paramters': key does not exist
>>> error = build_missing_key_error("lr", ["learning_rate"], parent_key="model")
>>> print(error._original_message)
Cannot remove non-existent key 'lr' from 'model'