Exceptions
DerivaML defines custom exceptions to provide clear error messages for common error conditions when working with catalogs, datasets, and executions.
Custom exceptions for the DerivaML package.
This module defines the exception hierarchy for DerivaML. All DerivaML-specific exceptions inherit from DerivaMLException, making it easy to catch all library errors with a single except clause.
Exception Hierarchy
DerivaMLException (base class for all DerivaML errors) │ ├── DerivaMLConfigurationError (configuration and initialization) │ ├── DerivaMLSchemaError (schema/catalog structure issues) │ └── DerivaMLAuthenticationError (authentication failures) │ ├── DerivaMLDataError (data access and validation) │ ├── DerivaMLNotFoundError (entity not found) │ │ ├── DerivaMLDatasetNotFound (dataset lookup failures) │ │ ├── DerivaMLTableNotFound (table lookup failures) │ │ └── DerivaMLInvalidTerm (vocabulary term not found) │ ├── DerivaMLTableTypeError (wrong table type) │ ├── DerivaMLValidationError (data validation failures) │ └── DerivaMLCycleError (cycle detected in relationships) │ ├── DerivaMLExecutionError (execution lifecycle) │ ├── DerivaMLWorkflowError (workflow issues) │ │ └── DerivaMLDirtyWorkflowError (uncommitted changes) │ └── DerivaMLUploadError (asset upload failures) │ └── DerivaMLReadOnlyError (write operation on read-only resource)
Example
from deriva_ml.core.exceptions import DerivaMLException, DerivaMLNotFoundError try: ... dataset = ml.lookup_dataset("invalid_rid") ... except DerivaMLDatasetNotFound as e: ... print(f"Dataset not found: {e}") ... except DerivaMLNotFoundError as e: ... print(f"Entity not found: {e}") ... except DerivaMLException as e: ... print(f"DerivaML error: {e}")
DerivaMLAuthenticationError
Bases: DerivaMLConfigurationError
Exception raised for authentication failures.
Raised when authentication with the catalog fails or credentials are invalid.
Example
raise DerivaMLAuthenticationError("Failed to authenticate with catalog")
Source code in src/deriva_ml/core/exceptions.py
96 97 98 99 100 101 102 103 104 105 | |
DerivaMLConfigurationError
Bases: DerivaMLException
Exception raised for configuration and initialization errors.
Raised when there are issues with DerivaML configuration, catalog initialization, or schema setup.
Example
raise DerivaMLConfigurationError("Invalid catalog configuration")
Source code in src/deriva_ml/core/exceptions.py
70 71 72 73 74 75 76 77 78 79 80 | |
DerivaMLCycleError
Bases: DerivaMLDataError
Exception raised when a cycle is detected in relationships.
Raised when creating dataset hierarchies or other relationships that would result in a circular dependency.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cycle_nodes
|
list[str]
|
List of nodes involved in the cycle. |
required |
msg
|
str
|
Additional context. Defaults to "Cycle detected". |
'Cycle detected'
|
Example
raise DerivaMLCycleError(["Dataset1", "Dataset2", "Dataset1"])
Source code in src/deriva_ml/core/exceptions.py
234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 | |
DerivaMLDataError
Bases: DerivaMLException
Exception raised for data access and validation issues.
Base class for errors related to data lookup, validation, and integrity.
Example
raise DerivaMLDataError("Invalid data format")
Source code in src/deriva_ml/core/exceptions.py
113 114 115 116 117 118 119 120 121 122 | |
DerivaMLDatasetNotFound
Bases: DerivaMLNotFoundError
Exception raised when a dataset cannot be found.
Raised when attempting to look up a dataset that doesn't exist in the catalog or downloaded bag.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dataset_rid
|
str
|
The RID of the dataset that was not found. |
required |
msg
|
str
|
Additional context. Defaults to "Dataset not found". |
'Dataset not found'
|
Example
raise DerivaMLDatasetNotFound("1-ABC") DerivaMLDatasetNotFound: Dataset 1-ABC not found
Source code in src/deriva_ml/core/exceptions.py
138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 | |
DerivaMLDirtyWorkflowError
Bases: DerivaMLWorkflowError
Exception raised when workflow code has uncommitted changes.
DerivaML requires code to be committed before execution for provenance tracking. Running with uncommitted changes means the execution record cannot reliably link back to the source code.
Use allow_dirty=True in the API or --allow-dirty on the CLI
to override this check when debugging or iterating.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
Path to the file with uncommitted changes. |
required |
Example
raise DerivaMLDirtyWorkflowError("src/models/train.py") DerivaMLDirtyWorkflowError: File src/models/train.py has uncommitted changes. ...
Source code in src/deriva_ml/core/exceptions.py
284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 | |
DerivaMLException
Bases: Exception
Base exception class for all DerivaML errors.
This is the root exception for all DerivaML-specific errors. Catching this exception will catch any error raised by the DerivaML library.
Attributes:
| Name | Type | Description |
|---|---|---|
_msg |
The error message stored for later access. |
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
msg
|
str
|
Descriptive error message. Defaults to empty string. |
''
|
Example
raise DerivaMLException("Failed to connect to catalog") DerivaMLException: Failed to connect to catalog
Source code in src/deriva_ml/core/exceptions.py
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 | |
DerivaMLExecutionError
Bases: DerivaMLException
Exception raised for execution lifecycle issues.
Base class for errors related to workflow execution, asset management, and provenance tracking.
Example
raise DerivaMLExecutionError("Execution failed to initialize")
Source code in src/deriva_ml/core/exceptions.py
258 259 260 261 262 263 264 265 266 267 268 | |
DerivaMLInvalidTerm
Bases: DerivaMLNotFoundError
Exception raised when a vocabulary term is not found or invalid.
Raised when attempting to look up or use a term that doesn't exist in a controlled vocabulary table, or when a term name/synonym cannot be resolved.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
vocabulary
|
str
|
Name of the vocabulary table being searched. |
required |
term
|
str
|
The term name that was not found. |
required |
msg
|
str
|
Additional context about the error. Defaults to "Term doesn't exist". |
"Term doesn't exist"
|
Example
raise DerivaMLInvalidTerm("Diagnosis", "unknown_condition") DerivaMLInvalidTerm: Invalid term unknown_condition in vocabulary Diagnosis: Term doesn't exist.
Source code in src/deriva_ml/core/exceptions.py
178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 | |
DerivaMLNotFoundError
Bases: DerivaMLDataError
Exception raised when an entity cannot be found.
Raised when a lookup operation fails to find the requested entity (dataset, table, term, etc.) in the catalog or bag.
Example
raise DerivaMLNotFoundError("Entity '1-ABC' not found in catalog")
Source code in src/deriva_ml/core/exceptions.py
125 126 127 128 129 130 131 132 133 134 135 | |
DerivaMLReadOnlyError
Bases: DerivaMLException
Exception raised when attempting write operations on read-only resources.
Raised when attempting to modify data in a downloaded bag or other read-only context where write operations are not supported.
Example
raise DerivaMLReadOnlyError("Cannot create datasets in a downloaded bag")
Source code in src/deriva_ml/core/exceptions.py
328 329 330 331 332 333 334 335 336 337 338 | |
DerivaMLSchemaError
Bases: DerivaMLConfigurationError
Exception raised for schema or catalog structure issues.
Raised when the catalog schema is invalid, missing required tables, or has structural problems that prevent normal operation.
Example
raise DerivaMLSchemaError("Ambiguous domain schema: ['Schema1', 'Schema2']")
Source code in src/deriva_ml/core/exceptions.py
83 84 85 86 87 88 89 90 91 92 93 | |
DerivaMLTableNotFound
Bases: DerivaMLNotFoundError
Exception raised when a table cannot be found.
Raised when attempting to access a table that doesn't exist in the catalog schema or downloaded bag.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
table_name
|
str
|
The name of the table that was not found. |
required |
msg
|
str
|
Additional context. Defaults to "Table not found". |
'Table not found'
|
Example
raise DerivaMLTableNotFound("MyTable") DerivaMLTableNotFound: Table not found: MyTable
Source code in src/deriva_ml/core/exceptions.py
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 | |
DerivaMLTableTypeError
Bases: DerivaMLDataError
Exception raised when a RID or table is not of the expected type.
Raised when an operation requires a specific table type (e.g., Dataset, Execution) but receives a RID or table reference of a different type.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
table_type
|
str
|
The expected table type (e.g., "Dataset", "Execution"). |
required |
table
|
str
|
The actual table name or RID that was provided. |
required |
Example
raise DerivaMLTableTypeError("Dataset", "1-ABC123") DerivaMLTableTypeError: Table 1-ABC123 is not of type Dataset.
Source code in src/deriva_ml/core/exceptions.py
200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 | |
DerivaMLUploadError
Bases: DerivaMLExecutionError
Exception raised for asset upload failures.
Raised when uploading assets to the catalog fails, including file uploads, metadata insertion, and provenance recording.
Example
raise DerivaMLUploadError("Failed to upload execution assets")
Source code in src/deriva_ml/core/exceptions.py
310 311 312 313 314 315 316 317 318 319 320 | |
DerivaMLValidationError
Bases: DerivaMLDataError
Exception raised when data validation fails.
Raised when input data fails validation, such as invalid RID format, mismatched metadata, or constraint violations.
Example
raise DerivaMLValidationError("Invalid RID format: ABC")
Source code in src/deriva_ml/core/exceptions.py
221 222 223 224 225 226 227 228 229 230 231 | |
DerivaMLWorkflowError
Bases: DerivaMLExecutionError
Exception raised for workflow-related issues.
Raised when there are problems with workflow lookup, creation, or Git integration for workflow tracking.
Example
raise DerivaMLWorkflowError("Not executing in a Git repository")
Source code in src/deriva_ml/core/exceptions.py
271 272 273 274 275 276 277 278 279 280 281 | |