API Reference¶
Everything on this page is generated directly from the docstrings and type annotations in the source, so it always matches the installed version.
Top-level package¶
The names below are re-exported from dataexcept itself, so
from dataexcept import ValidationError works without reaching into a
submodule.
dataexcept ¶
Top-level package for DataExcept.
Every exception the package defines is importable straight from here::
from dataexcept import ValidationError, ModelTrainingError
They all derive from :class:DataExceptError, so one clause catches every
operational exception this package raises::
except DataExceptError:
...
The domain modules (datascience_exceptions, pipeline_exceptions and so
on) remain importable and export the same objects, so both spellings work and
refer to the same classes.
DataExceptError ¶
Bases: Exception
Base class for every operational exception DataExcept raises.
Source code in dataexcept/base.py
with_failure_metadata ¶
Attach backend-informed metadata and return self for chaining.
Source code in dataexcept/base.py
UnpicklableCause ¶
Bases: DataExceptError
Stands in for a cause that could not be serialized.
__cause__ and __context__ must be exceptions, so the placeholder
used for ordinary attributes will not do here. Dropping the chain instead
would silently lose the reason for the failure.
Source code in dataexcept/base.py
UnpicklableValue ¶
Stands in for state that could not survive serialization.
Source code in dataexcept/base.py
BrokerConnectionError ¶
Bases: MessageBrokerError
Raised when a connection to the broker cannot be established.
Source code in dataexcept/broker_exceptions.py
BrokerTimeoutError ¶
Bases: MessageBrokerError
Raised when a broker operation exceeds its time limit.
Source code in dataexcept/broker_exceptions.py
MessageAcknowledgementError ¶
Bases: MessageBrokerError
Raised when acknowledging or committing a message fails.
Distinct from a consume failure on purpose: the message was read and processed, and it is the record of that which did not stick -- so it will be delivered again.
Source code in dataexcept/broker_exceptions.py
MessageBrokerError ¶
Bases: DataExceptError
Base exception for message-broker failures.
Catching this catches every broker failure the library raises, without catching a database or HTTP one.
Source code in dataexcept/broker_exceptions.py
MessageConsumeError ¶
Bases: MessageBrokerError
Raised when consuming a message fails.
Source code in dataexcept/broker_exceptions.py
MessagePublishError ¶
Bases: MessageBrokerError
Raised when publishing a message fails.
Source code in dataexcept/broker_exceptions.py
DatabaseConnectionError ¶
Bases: DatabaseError
Raised when connecting to the database fails.
Source code in dataexcept/database_exceptions.py
DatabaseError ¶
Bases: DataExceptError
Base exception for database-related errors.
Source code in dataexcept/database_exceptions.py
QueryExecutionError ¶
Bases: DatabaseError
Raised when a database query execution fails.
Source code in dataexcept/database_exceptions.py
TransactionError ¶
Bases: DatabaseError
Raised when a database transaction fails.
Source code in dataexcept/database_exceptions.py
BatchProcessingError ¶
Bases: DataEngineeringError
Raised when processing a data batch fails.
Source code in dataexcept/dataengineering_exceptions.py
DataEngineeringError ¶
Bases: DataExceptError
Base exception for data engineering errors.
Source code in dataexcept/dataengineering_exceptions.py
DataTransformationError ¶
Bases: DataEngineeringError
Raised when a data transformation step fails.
Source code in dataexcept/dataengineering_exceptions.py
DataWarehouseConnectionError ¶
Bases: DataEngineeringError
Raised when a connection to a data warehouse cannot be established.
Source code in dataexcept/dataengineering_exceptions.py
ETLJobError ¶
Bases: DataEngineeringError
Raised when an ETL job fails to complete successfully.
Source code in dataexcept/dataengineering_exceptions.py
MissingPartitionError ¶
Bases: DataEngineeringError
Raised when a required data partition is missing.
Source code in dataexcept/dataengineering_exceptions.py
SchemaEvolutionError ¶
Bases: DataEngineeringError
Raised when database schema evolution fails.
Source code in dataexcept/dataengineering_exceptions.py
BiasDetectionError ¶
Bases: DataScienceError
Raised when algorithmic bias exceeds an acceptable threshold.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
feature
|
str
|
Feature or group where bias was detected. |
required |
bias_score
|
float
|
Calculated bias metric. |
required |
threshold
|
float
|
Maximum acceptable bias metric. |
required |
message
|
Optional[str]
|
Optional custom message. |
None
|
Source code in dataexcept/datascience_exceptions/training.py
ConvergenceError ¶
Bases: ModelTrainingError
Raised when optimization fails to converge.
Attributes:
| Name | Type | Description |
|---|---|---|
iterations |
number of iterations run. |
Source code in dataexcept/datascience_exceptions/training.py
CrossValidationError ¶
Bases: DataScienceError
Failure during cross-validation procedure.
Source code in dataexcept/datascience_exceptions/training.py
DataAugmentationError ¶
Bases: DataScienceError
Raised when a data augmentation technique fails.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
technique
|
str
|
Name of the augmentation technique. |
required |
details
|
Optional[str]
|
Optional explanation of the failure. |
None
|
Source code in dataexcept/datascience_exceptions/ingestion.py
DataDriftError ¶
Bases: DataScienceError
Raised when data drift is detected beyond threshold.
Attributes:
| Name | Type | Description |
|---|---|---|
feature |
feature name. |
|
drift_score |
computed drift metric. |
Source code in dataexcept/datascience_exceptions/operations.py
DataExportError ¶
Bases: DataScienceError
Failed to export or write data to destination.
Source code in dataexcept/datascience_exceptions/operations.py
DataFormatError ¶
Bases: DataScienceError
Raised when input data is not in the expected format.
Source code in dataexcept/datascience_exceptions/ingestion.py
DataImbalanceError ¶
Bases: DataScienceError
Raised when class distribution is too imbalanced.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ratio
|
float
|
Observed minority-to-majority ratio. |
required |
threshold
|
float
|
Minimum acceptable ratio. |
required |
message
|
Optional[str]
|
Optional custom error message. |
None
|
Source code in dataexcept/datascience_exceptions/ingestion.py
DataLeakageError ¶
Bases: DataScienceError
Raised when data leakage is detected between train and test sets.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
feature
|
str
|
Name of the leaked feature. |
required |
stage
|
str
|
Stage where the leakage occurred. |
required |
message
|
Optional[str]
|
Optional custom message. |
None
|
Source code in dataexcept/datascience_exceptions/ingestion.py
DataLoadingError ¶
Bases: DataScienceError
Raised when loading data fails.
Attributes:
| Name | Type | Description |
|---|---|---|
source |
data source description (file path, URL). |
|
original |
underlying exception. |
Source code in dataexcept/datascience_exceptions/ingestion.py
DataNormalizationError ¶
Bases: DataScienceError
Raised when data normalization fails.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
method
|
str
|
Normalization technique identifier. |
required |
details
|
Optional[str]
|
Optional explanation of the failure. |
None
|
Source code in dataexcept/datascience_exceptions/ingestion.py
DataScienceError ¶
Bases: DataExceptError
Base exception for data science errors.
Source code in dataexcept/datascience_exceptions/base.py
DataValidationError ¶
Bases: DataScienceError
Raised when data fails validation rules.
Attributes:
| Name | Type | Description |
|---|---|---|
field |
name of invalid field. |
|
value |
the invalid value. |
Source code in dataexcept/datascience_exceptions/ingestion.py
DeploymentError ¶
Bases: DataScienceError
Raised when deploying a model or pipeline fails.
Attributes:
| Name | Type | Description |
|---|---|---|
target |
deployment target identifier. |
|
cause |
optional detail. |
Source code in dataexcept/datascience_exceptions/operations.py
DimensionalityReductionError ¶
Bases: DataScienceError
Error applying dimensionality reduction method.
Source code in dataexcept/datascience_exceptions/training.py
EarlyStoppingError ¶
Bases: DataScienceError
Raised when training stops early based on a stopping criterion.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
epoch
|
int
|
Epoch index where training stopped. |
required |
reason
|
Optional[str]
|
Optional reason for stopping. |
None
|
Source code in dataexcept/datascience_exceptions/training.py
ExperimentTrackingError ¶
Bases: DataScienceError
Issues logging or retrieving experiment metadata.
Source code in dataexcept/datascience_exceptions/training.py
ExplainabilityError ¶
Bases: DataScienceError
Raised when generating model explanations fails.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
method
|
str
|
Explanation technique identifier. |
required |
details
|
Optional[str]
|
Optional description of the failure. |
None
|
Source code in dataexcept/datascience_exceptions/training.py
FeatureEngineeringError ¶
Bases: DataScienceError
Raised during feature engineering steps.
Attributes:
| Name | Type | Description |
|---|---|---|
step |
description of the step that failed. |
|
cause |
optional underlying reason. |
Source code in dataexcept/datascience_exceptions/ingestion.py
FeatureScalingError ¶
Bases: DataScienceError
Raised when scaling or standardization of features fails.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
scaler
|
str
|
Name of the scaler or transformation used. |
required |
details
|
Optional[str]
|
Optional explanation of the failure. |
None
|
Source code in dataexcept/datascience_exceptions/training.py
FeatureSelectionError ¶
Bases: DataScienceError
Failure in feature selection procedure.
Source code in dataexcept/datascience_exceptions/training.py
GPUOutOfMemoryError ¶
Bases: DataScienceError
Model or tensor exceeds GPU memory capacity.
Source code in dataexcept/datascience_exceptions/training.py
HyperparameterError ¶
Bases: DataScienceError
Raised for invalid hyperparameter settings.
Attributes:
| Name | Type | Description |
|---|---|---|
param |
name of hyperparameter. |
|
value |
invalid value. |
Source code in dataexcept/datascience_exceptions/training.py
HyperparameterTuningError ¶
Bases: DataScienceError
Error during hyperparameter search or tuning.
Source code in dataexcept/datascience_exceptions/training.py
MissingDataError ¶
Bases: DataScienceError
Raised when required data is missing.
Attributes:
| Name | Type | Description |
|---|---|---|
feature |
name of missing feature. |
Source code in dataexcept/datascience_exceptions/ingestion.py
ModelCompatibilityError ¶
Bases: DataScienceError
Raised when a model is incompatible with the runtime environment.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
expected_version
|
str
|
Required model version. |
required |
found_version
|
str
|
Detected model version. |
required |
message
|
Optional[str]
|
Optional custom message. |
None
|
Source code in dataexcept/datascience_exceptions/training.py
ModelEvaluationError ¶
Bases: DataScienceError
Raised during evaluation metrics computation.
Attributes:
| Name | Type | Description |
|---|---|---|
metric |
name of the metric. |
|
value |
computed value. |
Source code in dataexcept/datascience_exceptions/training.py
ModelInferenceError ¶
Bases: DataScienceError
Raised when model inference fails.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_type
|
str
|
Identifier of the model used for inference. |
required |
original
|
Exception
|
Underlying exception raised by the model. |
required |
Source code in dataexcept/datascience_exceptions/training.py
ModelSerializationError ¶
Bases: DataScienceError
Raised when saving or loading a model fails.
Attributes:
| Name | Type | Description |
|---|---|---|
path |
file path involved. |
|
original |
underlying exception. |
Source code in dataexcept/datascience_exceptions/operations.py
ModelTrainingError ¶
Bases: DataScienceError
Raised when model training fails.
Attributes:
| Name | Type | Description |
|---|---|---|
model_type |
model class or name. |
|
epoch |
optional epoch index. |
Source code in dataexcept/datascience_exceptions/training.py
OutlierDetectionError ¶
Bases: DataScienceError
Raised when outlier detection fails.
Attributes:
| Name | Type | Description |
|---|---|---|
method |
detection method name. |
|
details |
optional extra info. |
Source code in dataexcept/datascience_exceptions/ingestion.py
OverfittingError ¶
Bases: DataScienceError
Raised when a model is overfitting the training data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
train_metric
|
float
|
Metric value on the training set. |
required |
val_metric
|
float
|
Metric value on the validation set. |
required |
Source code in dataexcept/datascience_exceptions/training.py
PredictionError ¶
Bases: DataScienceError
Raised when making predictions fails.
Attributes:
| Name | Type | Description |
|---|---|---|
model_type |
model used. |
|
inputs |
input data snapshot. |
Source code in dataexcept/datascience_exceptions/training.py
ResourceLimitError ¶
Bases: DataScienceError
Raised when computation exceeds resources (memory, CPU).
Attributes:
| Name | Type | Description |
|---|---|---|
resource |
'memory', 'cpu', etc. |
|
limit |
threshold exceeded. |
Source code in dataexcept/datascience_exceptions/operations.py
SchemaMismatchError ¶
Bases: DataScienceError
Raised when data schema does not match expected.
Attributes:
| Name | Type | Description |
|---|---|---|
expected |
expected schema description. |
|
found |
actual schema description. |
Source code in dataexcept/datascience_exceptions/ingestion.py
TrainingTimeoutError ¶
Bases: ModelTrainingError
Raised when model training exceeds a time limit.
Source code in dataexcept/datascience_exceptions/training.py
UnderfittingError ¶
Bases: DataScienceError
Raised when a model fails to capture patterns in the data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
train_metric
|
float
|
Metric value on the training set. |
required |
threshold
|
float
|
Minimum acceptable metric value. |
required |
Source code in dataexcept/datascience_exceptions/training.py
AuthenticationError ¶
Bases: JobError
Raised when user authentication fails.
Source code in dataexcept/exceptions/authentication.py
AuthorizationError ¶
Bases: JobError
Raised when user lacks permission for an action.
Source code in dataexcept/exceptions/authentication.py
ConfigurationError ¶
Bases: JobError
Raised when there is a problem with configuration or settings.
Source code in dataexcept/exceptions/configuration.py
CronExpressionError ¶
Bases: JobError
Raised when a cron expression is invalid.
Source code in dataexcept/exceptions/scheduling.py
DependencyError ¶
Bases: JobError
Raised when a job dependency is missing or fails.
Source code in dataexcept/exceptions/external.py
DeserializationError ¶
Bases: JobError
Raised when deserialization of data fails.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
bytes | None
|
The offending bytes. Optional, and kept verbatim when given: pass it only when the payload is yours and safe to retain. |
None
|
format
|
str | None
|
What the payload was meant to be, such as |
None
|
message
|
str | None
|
Overrides the generated message entirely. |
None
|
source
|
str | None
|
Where the payload came from -- an endpoint, path or queue. Redacted when it is a URL, left alone when it is a file path. |
None
|
preview
|
str | bytes | bytearray | None
|
A bounded excerpt of the payload, truncated to
:data: |
None
|
cause
|
Exception | None
|
The underlying exception, also set as |
None
|
Source code in dataexcept/exceptions/parsing.py
EmailError ¶
Bases: NotificationError
Raised when sending an email fails.
Source code in dataexcept/exceptions/notification.py
JobCancellationError ¶
Bases: JobError
Raised when a job is cancelled before completion.
Source code in dataexcept/exceptions/lifecycle.py
JobError ¶
Bases: DataExceptError
Base exception for all job-related errors.
Source code in dataexcept/exceptions/base.py
NotificationError ¶
Bases: JobError
Base exception for notification failures.
Source code in dataexcept/exceptions/notification.py
OperationTimeoutError ¶
Bases: JobError
Raised when an operation exceeds its time limit.
Source code in dataexcept/exceptions/external.py
ParsingError ¶
Bases: JobError
Raised when parsing of input data fails.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str | None
|
The offending content. Optional, and kept verbatim when given: pass it only when the content is yours and safe to retain. |
None
|
message
|
str | None
|
Overrides the generated message entirely. |
None
|
source
|
str | None
|
Where the content came from -- an endpoint, path or queue. Redacted when it is a URL, left alone when it is a file path. |
None
|
format
|
str | None
|
What the content was meant to be, such as |
None
|
preview
|
str | bytes | bytearray | None
|
A bounded excerpt of the content, truncated to
:data: |
None
|
cause
|
Exception | None
|
The underlying exception, also set as |
None
|
Source code in dataexcept/exceptions/parsing.py
ResourceNotFoundError ¶
Bases: JobError
Raised when a required resource cannot be found.
Source code in dataexcept/exceptions/external.py
ScheduleConflictError ¶
Bases: JobError
Raised when two jobs have conflicting schedules.
Source code in dataexcept/exceptions/scheduling.py
SerializationError ¶
Bases: JobError
Raised when serialization of an object fails.
Source code in dataexcept/exceptions/parsing.py
ServiceConnectionError ¶
Bases: JobError
Raised when a connection to an external service fails.
Source code in dataexcept/exceptions/external.py
ValidationError ¶
Bases: JobError
Raised when input data fails validation.
Source code in dataexcept/exceptions/validation.py
WebhookError ¶
Bases: NotificationError
Raised when a webhook POST fails.
Source code in dataexcept/exceptions/notification.py
FailureMetadata
dataclass
¶
Describe recovery-relevant properties of an operational failure.
failure_kind describes whether the underlying condition is known to be
transient, permanent for the same operation/payload, or unknown.
retryable is deliberately independent: DataExcept describes the
failure, while the calling application still owns retry policy.
Source code in dataexcept/failure_metadata.py
CustomIOError ¶
FileLockError ¶
Bases: CustomIOError
Raised when a file lock cannot be acquired.
Source code in dataexcept/io_exceptions.py
FileReadError ¶
Bases: CustomIOError
Raised when reading a file fails.
Source code in dataexcept/io_exceptions.py
FileWriteError ¶
Bases: CustomIOError
Raised when writing to a file fails.
Source code in dataexcept/io_exceptions.py
ConnectionTimeoutError ¶
Bases: NetworkError
Raised when a network connection attempt times out.
Example
from dataexcept.network_exceptions import ConnectionTimeoutError try: ... raise ConnectionTimeoutError("api.example.com", 30) ... except ConnectionTimeoutError as exc: ... print(exc) Connection to 'api.example.com' timed out after 30 seconds
Source code in dataexcept/network_exceptions.py
HostUnreachableError ¶
Bases: NetworkError
Raised when a remote host cannot be reached.
Example
from dataexcept.network_exceptions import HostUnreachableError try: ... raise HostUnreachableError("api.example.com") ... except HostUnreachableError as exc: ... print(exc) Host 'api.example.com' is unreachable
Source code in dataexcept/network_exceptions.py
NetworkError ¶
Bases: DataExceptError
Base exception for network-related errors.
Example
from dataexcept.network_exceptions import NetworkError try: ... raise NetworkError("Something went wrong") ... except NetworkError: ... print("Caught network error") Caught network error
Source code in dataexcept/network_exceptions.py
ProtocolError ¶
Bases: NetworkError
Raised when an unexpected protocol error occurs.
Example
from dataexcept.network_exceptions import ProtocolError try: ... raise ProtocolError("HTTP", "Invalid status line") ... except ProtocolError as exc: ... print(exc) Protocol error in HTTP: Invalid status line
Source code in dataexcept/network_exceptions.py
OperationContext
dataclass
¶
Identifiers that describe where an operation is executing.
system, component and operation are intended to stay
low-cardinality and are suitable for filtering. Request, job, correlation,
trace and span identifiers are correlation data and should not normally be
turned into metric dimensions or indexed tags.
Every value is optional because inventing provenance is worse than omitting it. URL-shaped values are redacted before they can leave this object.
Source code in dataexcept/observability.py
DtypeMismatchError ¶
Bases: PandasError
Raised when a column has an unexpected dtype.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
column
|
str
|
Name of the column. |
required |
expected
|
Sequence[str]
|
Sequence of allowed dtypes. |
required |
found
|
str
|
Detected dtype for the column. |
required |
Source code in dataexcept/pandas_exceptions.py
IndexAlignmentError ¶
Bases: PandasError
Raised when DataFrame indices are misaligned for an operation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
details
|
Optional[str]
|
Optional details about the misalignment. |
None
|
Source code in dataexcept/pandas_exceptions.py
MergeKeyError ¶
Bases: PandasError
Raised when merging DataFrames fails due to key issues.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
left_keys
|
Sequence[str]
|
Keys from the left DataFrame. |
required |
right_keys
|
Sequence[str]
|
Keys from the right DataFrame. |
required |
Source code in dataexcept/pandas_exceptions.py
MissingColumnError ¶
Bases: PandasError
Raised when a required DataFrame column is missing.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
column
|
str
|
Name of the missing column. |
required |
dataframe
|
Optional[str]
|
Optional name of the DataFrame being inspected. |
None
|
Source code in dataexcept/pandas_exceptions.py
PandasError ¶
Bases: DataExceptError
Base exception for pandas-related errors.
Source code in dataexcept/pandas_exceptions.py
PandasIOError ¶
Bases: PandasError
Raised when reading from or writing to disk with pandas fails.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
File path involved in the operation. |
required |
original
|
Exception
|
The underlying exception that was raised. |
required |
Source code in dataexcept/pandas_exceptions.py
ApiError ¶
Bases: PipelineError
Failure calling a REST API endpoint.
Source code in dataexcept/pipeline_exceptions.py
DataFetchError ¶
Bases: PipelineError
Failed to fetch data from a storage backend.
Source code in dataexcept/pipeline_exceptions.py
ExternalServiceError ¶
Bases: PipelineError
General failure when calling an external service.
Source code in dataexcept/pipeline_exceptions.py
FeaturePreprocessingError ¶
Bases: PreprocessingError
Raised when feature engineering fails.
Source code in dataexcept/pipeline_exceptions.py
PipelineError ¶
Bases: DataExceptError
Base exception for pipeline errors.
Source code in dataexcept/pipeline_exceptions.py
PipelineNotificationError ¶
Bases: PipelineError
Raised when sending a notification fails.
Source code in dataexcept/pipeline_exceptions.py
PreprocessingError ¶
Bases: PipelineError
Raised when a preprocessing step fails.
Source code in dataexcept/pipeline_exceptions.py
RetryLimitExceededError ¶
Bases: PipelineError
Raised when an operation is retried too many times.
Source code in dataexcept/pipeline_exceptions.py
ServiceAuthenticationError ¶
Bases: ExternalServiceError
Authentication to an external service failed.
Source code in dataexcept/pipeline_exceptions.py
ServiceAuthorizationError ¶
Bases: ExternalServiceError
Authorization was denied by an external service.
Source code in dataexcept/pipeline_exceptions.py
ServiceTimeoutError ¶
Bases: ExternalServiceError
A call to an external service exceeded the allotted time.
Source code in dataexcept/pipeline_exceptions.py
StorageError ¶
Bases: PipelineError
Raised when reading from or writing to storage fails.
Source code in dataexcept/pipeline_exceptions.py
TimeDeltaTooLargeError ¶
Bases: PipelineError
The time span between records exceeded a threshold.
Source code in dataexcept/pipeline_exceptions.py
TypeCheckError ¶
Bases: PipelineError
Invalid type detected during recursive type inspection.
Source code in dataexcept/pipeline_exceptions.py
DecryptionError ¶
Bases: SecurityError
Raised when data decryption fails.
Source code in dataexcept/security_exceptions.py
EncryptionError ¶
Bases: SecurityError
Raised when data encryption fails.
Source code in dataexcept/security_exceptions.py
InvalidTokenError ¶
Bases: SecurityError
Raised when an authentication token is invalid or expired.
Source code in dataexcept/security_exceptions.py
SecurityError ¶
Bases: DataExceptError
Base exception for security errors.
Source code in dataexcept/security_exceptions.py
log_and_raise ¶
log_and_raise(logger: Optional[Logger] = None, level: int = logging.ERROR, context: Context | None = None, operation_context: OperationContext | None = None) -> Iterator[None]
Context manager that logs and re-raises exceptions preserving traceback.
Source code in dataexcept/logging_helpers.py
log_exception ¶
log_exception(exc: Exception, logger: Optional[Logger] = None, level: int = logging.ERROR, context: Context | None = None, operation_context: OperationContext | None = None) -> None
Log exc at the given log level using logger.
If logger is None a module level logger is used.
context remains the free-form application context. operation_context
carries the stable request/job/tool-call identifiers shared with tracing and
error-tracker integrations.
DataExcept redacts what it renders, but a wrapped third-party exception
renders itself: an HTTP client's error may quote the credential-bearing URL
it was called with, and exc_info makes logging print that whole chain.
When the chain contains a URL the traceback is formatted and scrubbed here;
otherwise the structured exc_info path is used unchanged, so ordinary
exceptions keep the shape log aggregators expect.
Logging is fail-open: context conversion, traceback rendering or the logger itself may fail, but that failure is swallowed so observability can never replace the exception the caller was already handling.
Source code in dataexcept/logging_helpers.py
log_then_raise ¶
log_then_raise(exc: Exception, logger: Optional[Logger] = None, level: int = logging.ERROR, context: Context | None = None, operation_context: OperationContext | None = None) -> None
Log exc and immediately raise it.
This helper mirrors the pre-context-manager API for scenarios where adding a
with block would be too intrusive. Prefer :func:log_and_raise whenever
possible so tracebacks remain untouched.
Source code in dataexcept/logging_helpers.py
exception_to_observability_event ¶
exception_to_observability_event(exc: BaseException, *, operation_context: OperationContext | None = None, include_attributes: bool = True, max_depth: int = 8) -> dict[str, Any]
Return a strict-JSON-safe failure event shared by observability adapters.
The exception payload is the canonical DataExcept envelope. Operation metadata is separate so adapters can index stable fields while retaining high-cardinality correlation identifiers without flattening them into tags.
Source code in dataexcept/observability.py
envelope_to_pino ¶
Project envelope into the value Pino logs under its error key.
Pass stack only when a real stack representation is in hand -- the
traceback the failure actually carried, or a stack a caller received across
a boundary. It is redacted like every other exported string.
Source code in dataexcept/pino.py
exception_to_pino ¶
exception_to_pino(exc: BaseException, *, include_attributes: bool = True, max_depth: int = 8, include_stack: bool = False) -> dict[str, Any]
Return exc in Pino's shape, by way of its envelope.
include_stack renders the exception's own traceback when it has one.
The field is omitted rather than invented when it does not.
Source code in dataexcept/pino.py
envelope_schema ¶
Return the JSON Schema describing an exception envelope.
The result is a fresh copy on every call, so a caller that registers it with a validator, or annotates it for an API specification, cannot corrupt the copy the next caller gets.
Source code in dataexcept/schema.py
pino_profile_schema ¶
Return the JSON Schema describing the Pino projection of an envelope.
A fresh copy on every call, for the same reason as
:func:envelope_schema.
Source code in dataexcept/schema.py
enrich_sentry_event ¶
enrich_sentry_event(event: dict[str, Any], hint: Mapping[str, Any], *, operation_context: OperationContext | None = None, include_attributes: bool = True, max_depth: int = 8) -> dict[str, Any]
Return a Sentry event enriched with DataExcept failure metadata.
Full operation context, including correlation identifiers, is stored under
contexts.dataexcept_operation. Only the low-cardinality operation fields
become tags so request/job/trace identifiers do not become indexed tags.
Source code in dataexcept/sentry.py
exception_to_dict ¶
exception_to_dict(exc: BaseException, *, include_attributes: bool = True, max_depth: int = 8) -> dict[str, Any]
Return a strict JSON-safe structured representation of exc.
Source code in dataexcept/serialization.py
exception_to_json ¶
exception_to_json(exc: BaseException, *, include_attributes: bool = True, max_depth: int = 8, **json_kwargs: Any) -> str
Return :func:exception_to_dict encoded as strict JSON.
Source code in dataexcept/serialization.py
wrap ¶
wrap(original: BaseException, target: Type[DataExceptError], /, *, failure_metadata: FailureMetadata | None = None, **kwargs: Any) -> DataExceptError
Build target from original, recording it as the cause.
Extra keyword arguments are passed through to the target constructor. If
the target accepts a cause parameter, original is injected unless the
caller already supplied cause, original or original_exception.
The resulting exception is always chained to original via __cause__.
failure_metadata optionally overrides the target class's conservative
default when the integration has backend-specific evidence about whether
the failure is transient or retryable.
Source code in dataexcept/wrapping.py
Core job exceptions¶
exceptions ¶
AuthenticationError ¶
Bases: JobError
Raised when user authentication fails.
Source code in dataexcept/exceptions/authentication.py
AuthorizationError ¶
Bases: JobError
Raised when user lacks permission for an action.
Source code in dataexcept/exceptions/authentication.py
JobError ¶
Bases: DataExceptError
Base exception for all job-related errors.
Source code in dataexcept/exceptions/base.py
ConfigurationError ¶
Bases: JobError
Raised when there is a problem with configuration or settings.
Source code in dataexcept/exceptions/configuration.py
DependencyError ¶
Bases: JobError
Raised when a job dependency is missing or fails.
Source code in dataexcept/exceptions/external.py
OperationTimeoutError ¶
Bases: JobError
Raised when an operation exceeds its time limit.
Source code in dataexcept/exceptions/external.py
ResourceNotFoundError ¶
Bases: JobError
Raised when a required resource cannot be found.
Source code in dataexcept/exceptions/external.py
ServiceConnectionError ¶
Bases: JobError
Raised when a connection to an external service fails.
Source code in dataexcept/exceptions/external.py
JobCancellationError ¶
Bases: JobError
Raised when a job is cancelled before completion.
Source code in dataexcept/exceptions/lifecycle.py
EmailError ¶
Bases: NotificationError
Raised when sending an email fails.
Source code in dataexcept/exceptions/notification.py
NotificationError ¶
Bases: JobError
Base exception for notification failures.
Source code in dataexcept/exceptions/notification.py
WebhookError ¶
Bases: NotificationError
Raised when a webhook POST fails.
Source code in dataexcept/exceptions/notification.py
DeserializationError ¶
Bases: JobError
Raised when deserialization of data fails.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
bytes | None
|
The offending bytes. Optional, and kept verbatim when given: pass it only when the payload is yours and safe to retain. |
None
|
format
|
str | None
|
What the payload was meant to be, such as |
None
|
message
|
str | None
|
Overrides the generated message entirely. |
None
|
source
|
str | None
|
Where the payload came from -- an endpoint, path or queue. Redacted when it is a URL, left alone when it is a file path. |
None
|
preview
|
str | bytes | bytearray | None
|
A bounded excerpt of the payload, truncated to
:data: |
None
|
cause
|
Exception | None
|
The underlying exception, also set as |
None
|
Source code in dataexcept/exceptions/parsing.py
ParsingError ¶
Bases: JobError
Raised when parsing of input data fails.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str | None
|
The offending content. Optional, and kept verbatim when given: pass it only when the content is yours and safe to retain. |
None
|
message
|
str | None
|
Overrides the generated message entirely. |
None
|
source
|
str | None
|
Where the content came from -- an endpoint, path or queue. Redacted when it is a URL, left alone when it is a file path. |
None
|
format
|
str | None
|
What the content was meant to be, such as |
None
|
preview
|
str | bytes | bytearray | None
|
A bounded excerpt of the content, truncated to
:data: |
None
|
cause
|
Exception | None
|
The underlying exception, also set as |
None
|
Source code in dataexcept/exceptions/parsing.py
SerializationError ¶
Bases: JobError
Raised when serialization of an object fails.
Source code in dataexcept/exceptions/parsing.py
CronExpressionError ¶
Bases: JobError
Raised when a cron expression is invalid.
Source code in dataexcept/exceptions/scheduling.py
ScheduleConflictError ¶
Bases: JobError
Raised when two jobs have conflicting schedules.
Source code in dataexcept/exceptions/scheduling.py
ValidationError ¶
Bases: JobError
Raised when input data fails validation.
Source code in dataexcept/exceptions/validation.py
Data science exceptions¶
datascience_exceptions ¶
Custom exceptions for data science workflows.
DataScienceError ¶
Bases: DataExceptError
Base exception for data science errors.
Source code in dataexcept/datascience_exceptions/base.py
DataAugmentationError ¶
Bases: DataScienceError
Raised when a data augmentation technique fails.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
technique
|
str
|
Name of the augmentation technique. |
required |
details
|
Optional[str]
|
Optional explanation of the failure. |
None
|
Source code in dataexcept/datascience_exceptions/ingestion.py
DataFormatError ¶
Bases: DataScienceError
Raised when input data is not in the expected format.
Source code in dataexcept/datascience_exceptions/ingestion.py
DataImbalanceError ¶
Bases: DataScienceError
Raised when class distribution is too imbalanced.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ratio
|
float
|
Observed minority-to-majority ratio. |
required |
threshold
|
float
|
Minimum acceptable ratio. |
required |
message
|
Optional[str]
|
Optional custom error message. |
None
|
Source code in dataexcept/datascience_exceptions/ingestion.py
DataLeakageError ¶
Bases: DataScienceError
Raised when data leakage is detected between train and test sets.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
feature
|
str
|
Name of the leaked feature. |
required |
stage
|
str
|
Stage where the leakage occurred. |
required |
message
|
Optional[str]
|
Optional custom message. |
None
|
Source code in dataexcept/datascience_exceptions/ingestion.py
DataLoadingError ¶
Bases: DataScienceError
Raised when loading data fails.
Attributes:
| Name | Type | Description |
|---|---|---|
source |
data source description (file path, URL). |
|
original |
underlying exception. |
Source code in dataexcept/datascience_exceptions/ingestion.py
DataNormalizationError ¶
Bases: DataScienceError
Raised when data normalization fails.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
method
|
str
|
Normalization technique identifier. |
required |
details
|
Optional[str]
|
Optional explanation of the failure. |
None
|
Source code in dataexcept/datascience_exceptions/ingestion.py
DataValidationError ¶
Bases: DataScienceError
Raised when data fails validation rules.
Attributes:
| Name | Type | Description |
|---|---|---|
field |
name of invalid field. |
|
value |
the invalid value. |
Source code in dataexcept/datascience_exceptions/ingestion.py
FeatureEngineeringError ¶
Bases: DataScienceError
Raised during feature engineering steps.
Attributes:
| Name | Type | Description |
|---|---|---|
step |
description of the step that failed. |
|
cause |
optional underlying reason. |
Source code in dataexcept/datascience_exceptions/ingestion.py
MissingDataError ¶
Bases: DataScienceError
Raised when required data is missing.
Attributes:
| Name | Type | Description |
|---|---|---|
feature |
name of missing feature. |
Source code in dataexcept/datascience_exceptions/ingestion.py
OutlierDetectionError ¶
Bases: DataScienceError
Raised when outlier detection fails.
Attributes:
| Name | Type | Description |
|---|---|---|
method |
detection method name. |
|
details |
optional extra info. |
Source code in dataexcept/datascience_exceptions/ingestion.py
SchemaMismatchError ¶
Bases: DataScienceError
Raised when data schema does not match expected.
Attributes:
| Name | Type | Description |
|---|---|---|
expected |
expected schema description. |
|
found |
actual schema description. |
Source code in dataexcept/datascience_exceptions/ingestion.py
DataDriftError ¶
Bases: DataScienceError
Raised when data drift is detected beyond threshold.
Attributes:
| Name | Type | Description |
|---|---|---|
feature |
feature name. |
|
drift_score |
computed drift metric. |
Source code in dataexcept/datascience_exceptions/operations.py
DataExportError ¶
Bases: DataScienceError
Failed to export or write data to destination.
Source code in dataexcept/datascience_exceptions/operations.py
DeploymentError ¶
Bases: DataScienceError
Raised when deploying a model or pipeline fails.
Attributes:
| Name | Type | Description |
|---|---|---|
target |
deployment target identifier. |
|
cause |
optional detail. |
Source code in dataexcept/datascience_exceptions/operations.py
ModelSerializationError ¶
Bases: DataScienceError
Raised when saving or loading a model fails.
Attributes:
| Name | Type | Description |
|---|---|---|
path |
file path involved. |
|
original |
underlying exception. |
Source code in dataexcept/datascience_exceptions/operations.py
ResourceLimitError ¶
Bases: DataScienceError
Raised when computation exceeds resources (memory, CPU).
Attributes:
| Name | Type | Description |
|---|---|---|
resource |
'memory', 'cpu', etc. |
|
limit |
threshold exceeded. |
Source code in dataexcept/datascience_exceptions/operations.py
BiasDetectionError ¶
Bases: DataScienceError
Raised when algorithmic bias exceeds an acceptable threshold.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
feature
|
str
|
Feature or group where bias was detected. |
required |
bias_score
|
float
|
Calculated bias metric. |
required |
threshold
|
float
|
Maximum acceptable bias metric. |
required |
message
|
Optional[str]
|
Optional custom message. |
None
|
Source code in dataexcept/datascience_exceptions/training.py
ConvergenceError ¶
Bases: ModelTrainingError
Raised when optimization fails to converge.
Attributes:
| Name | Type | Description |
|---|---|---|
iterations |
number of iterations run. |
Source code in dataexcept/datascience_exceptions/training.py
CrossValidationError ¶
Bases: DataScienceError
Failure during cross-validation procedure.
Source code in dataexcept/datascience_exceptions/training.py
DimensionalityReductionError ¶
Bases: DataScienceError
Error applying dimensionality reduction method.
Source code in dataexcept/datascience_exceptions/training.py
EarlyStoppingError ¶
Bases: DataScienceError
Raised when training stops early based on a stopping criterion.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
epoch
|
int
|
Epoch index where training stopped. |
required |
reason
|
Optional[str]
|
Optional reason for stopping. |
None
|
Source code in dataexcept/datascience_exceptions/training.py
ExperimentTrackingError ¶
Bases: DataScienceError
Issues logging or retrieving experiment metadata.
Source code in dataexcept/datascience_exceptions/training.py
ExplainabilityError ¶
Bases: DataScienceError
Raised when generating model explanations fails.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
method
|
str
|
Explanation technique identifier. |
required |
details
|
Optional[str]
|
Optional description of the failure. |
None
|
Source code in dataexcept/datascience_exceptions/training.py
FeatureScalingError ¶
Bases: DataScienceError
Raised when scaling or standardization of features fails.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
scaler
|
str
|
Name of the scaler or transformation used. |
required |
details
|
Optional[str]
|
Optional explanation of the failure. |
None
|
Source code in dataexcept/datascience_exceptions/training.py
FeatureSelectionError ¶
Bases: DataScienceError
Failure in feature selection procedure.
Source code in dataexcept/datascience_exceptions/training.py
GPUOutOfMemoryError ¶
Bases: DataScienceError
Model or tensor exceeds GPU memory capacity.
Source code in dataexcept/datascience_exceptions/training.py
HyperparameterError ¶
Bases: DataScienceError
Raised for invalid hyperparameter settings.
Attributes:
| Name | Type | Description |
|---|---|---|
param |
name of hyperparameter. |
|
value |
invalid value. |
Source code in dataexcept/datascience_exceptions/training.py
HyperparameterTuningError ¶
Bases: DataScienceError
Error during hyperparameter search or tuning.
Source code in dataexcept/datascience_exceptions/training.py
ModelCompatibilityError ¶
Bases: DataScienceError
Raised when a model is incompatible with the runtime environment.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
expected_version
|
str
|
Required model version. |
required |
found_version
|
str
|
Detected model version. |
required |
message
|
Optional[str]
|
Optional custom message. |
None
|
Source code in dataexcept/datascience_exceptions/training.py
ModelEvaluationError ¶
Bases: DataScienceError
Raised during evaluation metrics computation.
Attributes:
| Name | Type | Description |
|---|---|---|
metric |
name of the metric. |
|
value |
computed value. |
Source code in dataexcept/datascience_exceptions/training.py
ModelInferenceError ¶
Bases: DataScienceError
Raised when model inference fails.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_type
|
str
|
Identifier of the model used for inference. |
required |
original
|
Exception
|
Underlying exception raised by the model. |
required |
Source code in dataexcept/datascience_exceptions/training.py
ModelTrainingError ¶
Bases: DataScienceError
Raised when model training fails.
Attributes:
| Name | Type | Description |
|---|---|---|
model_type |
model class or name. |
|
epoch |
optional epoch index. |
Source code in dataexcept/datascience_exceptions/training.py
OverfittingError ¶
Bases: DataScienceError
Raised when a model is overfitting the training data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
train_metric
|
float
|
Metric value on the training set. |
required |
val_metric
|
float
|
Metric value on the validation set. |
required |
Source code in dataexcept/datascience_exceptions/training.py
PredictionError ¶
Bases: DataScienceError
Raised when making predictions fails.
Attributes:
| Name | Type | Description |
|---|---|---|
model_type |
model used. |
|
inputs |
input data snapshot. |
Source code in dataexcept/datascience_exceptions/training.py
TrainingTimeoutError ¶
Bases: ModelTrainingError
Raised when model training exceeds a time limit.
Source code in dataexcept/datascience_exceptions/training.py
UnderfittingError ¶
Bases: DataScienceError
Raised when a model fails to capture patterns in the data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
train_metric
|
float
|
Metric value on the training set. |
required |
threshold
|
float
|
Minimum acceptable metric value. |
required |
Source code in dataexcept/datascience_exceptions/training.py
Data engineering exceptions¶
dataengineering_exceptions ¶
Custom exceptions for data engineering workflows.
DataEngineeringError ¶
Bases: DataExceptError
Base exception for data engineering errors.
Source code in dataexcept/dataengineering_exceptions.py
ETLJobError ¶
Bases: DataEngineeringError
Raised when an ETL job fails to complete successfully.
Source code in dataexcept/dataengineering_exceptions.py
SchemaEvolutionError ¶
Bases: DataEngineeringError
Raised when database schema evolution fails.
Source code in dataexcept/dataengineering_exceptions.py
DataTransformationError ¶
Bases: DataEngineeringError
Raised when a data transformation step fails.
Source code in dataexcept/dataengineering_exceptions.py
BatchProcessingError ¶
Bases: DataEngineeringError
Raised when processing a data batch fails.
Source code in dataexcept/dataengineering_exceptions.py
DataWarehouseConnectionError ¶
Bases: DataEngineeringError
Raised when a connection to a data warehouse cannot be established.
Source code in dataexcept/dataengineering_exceptions.py
MissingPartitionError ¶
Bases: DataEngineeringError
Raised when a required data partition is missing.
Source code in dataexcept/dataengineering_exceptions.py
Pipeline exceptions¶
pipeline_exceptions ¶
Additional exception classes for data pipeline workflows.
PipelineError ¶
Bases: DataExceptError
Base exception for pipeline errors.
Source code in dataexcept/pipeline_exceptions.py
PreprocessingError ¶
Bases: PipelineError
Raised when a preprocessing step fails.
Source code in dataexcept/pipeline_exceptions.py
FeaturePreprocessingError ¶
Bases: PreprocessingError
Raised when feature engineering fails.
Source code in dataexcept/pipeline_exceptions.py
StorageError ¶
Bases: PipelineError
Raised when reading from or writing to storage fails.
Source code in dataexcept/pipeline_exceptions.py
PipelineNotificationError ¶
Bases: PipelineError
Raised when sending a notification fails.
Source code in dataexcept/pipeline_exceptions.py
RetryLimitExceededError ¶
Bases: PipelineError
Raised when an operation is retried too many times.
Source code in dataexcept/pipeline_exceptions.py
ExternalServiceError ¶
Bases: PipelineError
General failure when calling an external service.
Source code in dataexcept/pipeline_exceptions.py
ServiceAuthenticationError ¶
Bases: ExternalServiceError
Authentication to an external service failed.
Source code in dataexcept/pipeline_exceptions.py
ServiceAuthorizationError ¶
Bases: ExternalServiceError
Authorization was denied by an external service.
Source code in dataexcept/pipeline_exceptions.py
ServiceTimeoutError ¶
Bases: ExternalServiceError
A call to an external service exceeded the allotted time.
Source code in dataexcept/pipeline_exceptions.py
ApiError ¶
Bases: PipelineError
Failure calling a REST API endpoint.
Source code in dataexcept/pipeline_exceptions.py
TimeDeltaTooLargeError ¶
Bases: PipelineError
The time span between records exceeded a threshold.
Source code in dataexcept/pipeline_exceptions.py
TypeCheckError ¶
Bases: PipelineError
Invalid type detected during recursive type inspection.
Source code in dataexcept/pipeline_exceptions.py
DataFetchError ¶
Bases: PipelineError
Failed to fetch data from a storage backend.
Source code in dataexcept/pipeline_exceptions.py
Database exceptions¶
database_exceptions ¶
Custom exceptions for database operations.
DatabaseError ¶
Bases: DataExceptError
Base exception for database-related errors.
Source code in dataexcept/database_exceptions.py
DatabaseConnectionError ¶
Bases: DatabaseError
Raised when connecting to the database fails.
Source code in dataexcept/database_exceptions.py
QueryExecutionError ¶
Bases: DatabaseError
Raised when a database query execution fails.
Source code in dataexcept/database_exceptions.py
TransactionError ¶
Bases: DatabaseError
Raised when a database transaction fails.
Source code in dataexcept/database_exceptions.py
Message broker exceptions¶
broker_exceptions ¶
Custom exceptions for message-broker operations.
A broker is a data-engineering boundary like a database or an object store, and
it fails in ways that are specific to it: a publish is rejected, a consumer
cannot reach its group, an offset is never committed. Mapping those onto
ServiceConnectionError and OperationTimeoutError loses which of them
happened, and with it the topic, partition, offset and consumer group that say
where.
The hierarchy is deliberately about the operation rather than the product. Kafka, RabbitMQ, Pulsar and NATS disagree about almost everything else, but all four connect, publish, consume and acknowledge, so a pipeline can catch these without knowing which broker or client library is underneath -- and DataExcept depends on none of them.
Failure metadata stays at the conservative default. A broker refusing a publish
may be a leader election that resolves in a second or a topic that does not
exist, and the exception cannot tell which. An integration that does know --
because it read the broker's own error code -- attaches that with
with_failure_metadata or wrap(..., failure_metadata=...).
MessageBrokerError ¶
Bases: DataExceptError
Base exception for message-broker failures.
Catching this catches every broker failure the library raises, without catching a database or HTTP one.
Source code in dataexcept/broker_exceptions.py
BrokerConnectionError ¶
Bases: MessageBrokerError
Raised when a connection to the broker cannot be established.
Source code in dataexcept/broker_exceptions.py
BrokerTimeoutError ¶
Bases: MessageBrokerError
Raised when a broker operation exceeds its time limit.
Source code in dataexcept/broker_exceptions.py
MessagePublishError ¶
Bases: MessageBrokerError
Raised when publishing a message fails.
Source code in dataexcept/broker_exceptions.py
MessageConsumeError ¶
Bases: MessageBrokerError
Raised when consuming a message fails.
Source code in dataexcept/broker_exceptions.py
MessageAcknowledgementError ¶
Bases: MessageBrokerError
Raised when acknowledging or committing a message fails.
Distinct from a consume failure on purpose: the message was read and processed, and it is the record of that which did not stick -- so it will be delivered again.
Source code in dataexcept/broker_exceptions.py
Message broker observability context¶
broker_context ¶
Framework-neutral broker and stream-processing observability context.
The adapter accepts plain message metadata so Kafka, RabbitMQ, Pulsar, NATS, stream processors and custom brokers can share one dependency-free boundary model. Message bodies and application payloads are intentionally excluded.
BrokerContext ¶
Broker operation context plus optional message coordinates.
Source code in dataexcept/broker_context.py
broker_context_from_message ¶
broker_context_from_message(operation: str, topic: str, *, metadata: Mapping[str, object] | None = None, system: str | None = 'broker', component: str | None = None, correlation_id: str | None = None, partition: int | None = None, offset: int | None = None, consumer_group: str | None = None, message_id: str | None = None) -> BrokerContext
Build observability context for a broker or stream-processing boundary.
The stable operation identity is "
Source code in dataexcept/broker_context.py
I/O exceptions¶
io_exceptions ¶
Custom exceptions for file and I/O operations.
CustomIOError ¶
FileReadError ¶
Bases: CustomIOError
Raised when reading a file fails.
Source code in dataexcept/io_exceptions.py
FileWriteError ¶
Bases: CustomIOError
Raised when writing to a file fails.
Source code in dataexcept/io_exceptions.py
FileLockError ¶
Bases: CustomIOError
Raised when a file lock cannot be acquired.
Source code in dataexcept/io_exceptions.py
Network exceptions¶
network_exceptions ¶
Custom exceptions for network operations.
NetworkError ¶
Bases: DataExceptError
Base exception for network-related errors.
Example
from dataexcept.network_exceptions import NetworkError try: ... raise NetworkError("Something went wrong") ... except NetworkError: ... print("Caught network error") Caught network error
Source code in dataexcept/network_exceptions.py
HostUnreachableError ¶
Bases: NetworkError
Raised when a remote host cannot be reached.
Example
from dataexcept.network_exceptions import HostUnreachableError try: ... raise HostUnreachableError("api.example.com") ... except HostUnreachableError as exc: ... print(exc) Host 'api.example.com' is unreachable
Source code in dataexcept/network_exceptions.py
ConnectionTimeoutError ¶
Bases: NetworkError
Raised when a network connection attempt times out.
Example
from dataexcept.network_exceptions import ConnectionTimeoutError try: ... raise ConnectionTimeoutError("api.example.com", 30) ... except ConnectionTimeoutError as exc: ... print(exc) Connection to 'api.example.com' timed out after 30 seconds
Source code in dataexcept/network_exceptions.py
ProtocolError ¶
Bases: NetworkError
Raised when an unexpected protocol error occurs.
Example
from dataexcept.network_exceptions import ProtocolError try: ... raise ProtocolError("HTTP", "Invalid status line") ... except ProtocolError as exc: ... print(exc) Protocol error in HTTP: Invalid status line
Source code in dataexcept/network_exceptions.py
pandas exceptions¶
pandas_exceptions ¶
Custom exceptions for pandas DataFrame operations.
PandasError ¶
Bases: DataExceptError
Base exception for pandas-related errors.
Source code in dataexcept/pandas_exceptions.py
MissingColumnError ¶
Bases: PandasError
Raised when a required DataFrame column is missing.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
column
|
str
|
Name of the missing column. |
required |
dataframe
|
Optional[str]
|
Optional name of the DataFrame being inspected. |
None
|
Source code in dataexcept/pandas_exceptions.py
DtypeMismatchError ¶
Bases: PandasError
Raised when a column has an unexpected dtype.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
column
|
str
|
Name of the column. |
required |
expected
|
Sequence[str]
|
Sequence of allowed dtypes. |
required |
found
|
str
|
Detected dtype for the column. |
required |
Source code in dataexcept/pandas_exceptions.py
IndexAlignmentError ¶
Bases: PandasError
Raised when DataFrame indices are misaligned for an operation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
details
|
Optional[str]
|
Optional details about the misalignment. |
None
|
Source code in dataexcept/pandas_exceptions.py
MergeKeyError ¶
Bases: PandasError
Raised when merging DataFrames fails due to key issues.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
left_keys
|
Sequence[str]
|
Keys from the left DataFrame. |
required |
right_keys
|
Sequence[str]
|
Keys from the right DataFrame. |
required |
Source code in dataexcept/pandas_exceptions.py
PandasIOError ¶
Bases: PandasError
Raised when reading from or writing to disk with pandas fails.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
File path involved in the operation. |
required |
original
|
Exception
|
The underlying exception that was raised. |
required |
Source code in dataexcept/pandas_exceptions.py
Security exceptions¶
security_exceptions ¶
Custom exceptions for security-related operations.
SecurityError ¶
Bases: DataExceptError
Base exception for security errors.
Source code in dataexcept/security_exceptions.py
EncryptionError ¶
Bases: SecurityError
Raised when data encryption fails.
Source code in dataexcept/security_exceptions.py
DecryptionError ¶
Bases: SecurityError
Raised when data decryption fails.
Source code in dataexcept/security_exceptions.py
InvalidTokenError ¶
Bases: SecurityError
Raised when an authentication token is invalid or expired.
Source code in dataexcept/security_exceptions.py
Observability model¶
observability ¶
Product-neutral observability context for failures crossing boundaries.
Frameworks call the same concepts by different names: request, task, job, workflow step, tool call, invocation. DataExcept keeps the shared part small and explicit so adapters can project it into logs, traces, error trackers or protocol-specific metadata without making those frameworks runtime requirements.
OperationContext
dataclass
¶
Identifiers that describe where an operation is executing.
system, component and operation are intended to stay
low-cardinality and are suitable for filtering. Request, job, correlation,
trace and span identifiers are correlation data and should not normally be
turned into metric dimensions or indexed tags.
Every value is optional because inventing provenance is worse than omitting it. URL-shaped values are redacted before they can leave this object.
Source code in dataexcept/observability.py
exception_to_observability_event ¶
exception_to_observability_event(exc: BaseException, *, operation_context: OperationContext | None = None, include_attributes: bool = True, max_depth: int = 8) -> dict[str, Any]
Return a strict-JSON-safe failure event shared by observability adapters.
The exception payload is the canonical DataExcept envelope. Operation metadata is separate so adapters can index stable fields while retaining high-cardinality correlation identifiers without flattening them into tags.
Source code in dataexcept/observability.py
OpenTelemetry adapter¶
opentelemetry ¶
OpenTelemetry-compatible exception attributes without an OTel dependency.
OpenTelemetry defines stable exception.type, exception.message and
exception.stacktrace attributes for exceptions. DataExcept can supply those
values from its redacted envelope, plus its recovery metadata and product-neutral
operation context, without importing opentelemetry itself.
ExceptionRecorder ¶
Bases: Protocol
Minimal structural interface required by :func:record_otel_exception.
Source code in dataexcept/opentelemetry.py
record_exception ¶
exception_to_otel_attributes ¶
exception_to_otel_attributes(exc: BaseException, *, operation_context: OperationContext | None = None, include_attributes: bool = True, max_depth: int = 8, include_stacktrace: bool = True, include_envelope: bool = False) -> dict[str, OtelAttributeValue]
Return OpenTelemetry-compatible attributes describing exc.
trace_id and span_id from :class:OperationContext are deliberately
not duplicated as custom attributes. OpenTelemetry already carries them in
native span context; DataExcept only projects operation and correlation data.
Source code in dataexcept/opentelemetry.py
record_otel_exception ¶
record_otel_exception(span: ExceptionRecorder, exc: BaseException, *, operation_context: OperationContext | None = None, include_attributes: bool = True, max_depth: int = 8, include_stacktrace: bool = True, include_envelope: bool = False) -> None
Record exc without allowing telemetry failure to escape.
Attribute conversion remains strict through
:func:exception_to_otel_attributes. This emission helper is different:
it is intended for use while handling an existing failure, so conversion or
recorder errors are swallowed rather than replacing that failure.
Source code in dataexcept/opentelemetry.py
Sentry adapter¶
sentry ¶
Enrich Sentry error events with structured DataExcept metadata.
enrich_sentry_event ¶
enrich_sentry_event(event: dict[str, Any], hint: Mapping[str, Any], *, operation_context: OperationContext | None = None, include_attributes: bool = True, max_depth: int = 8) -> dict[str, Any]
Return a Sentry event enriched with DataExcept failure metadata.
Full operation context, including correlation identifiers, is stored under
contexts.dataexcept_operation. Only the low-cardinality operation fields
become tags so request/job/trace identifiers do not become indexed tags.
Source code in dataexcept/sentry.py
W3C Trace Context¶
trace_context ¶
W3C Trace Context parsing without a tracing runtime dependency.
DataExcept only needs enough trace context to keep failures correlated across execution boundaries. It does not start spans or generate identifiers. The raw carrier values are preserved for forwarding, while parsed identifiers are available to logging, error-tracker and protocol adapters.
W3CTraceContext
dataclass
¶
Parsed W3C traceparent plus optional propagation companions.
parent_id is the caller's span identifier from the incoming carrier.
It is deliberately not treated as the local OperationContext.span_id.
traceparent is retained verbatim so pass-through code can forward an
unknown future version without reconstructing fields it does not understand.
Source code in dataexcept/trace_context.py
to_carrier ¶
Return propagation fields without changing their received values.
Source code in dataexcept/trace_context.py
to_operation_context ¶
Return context correlated with this trace without inventing a span.
Existing operation metadata is preserved. A conflicting trace ID is rejected because silently replacing provenance would make correlation less trustworthy than omitting it.
Source code in dataexcept/trace_context.py
parse_traceparent ¶
parse_traceparent(value: str, *, tracestate: str | None = None, baggage: str | None = None) -> W3CTraceContext | None
Parse a W3C traceparent value, returning None when invalid.
Version 00 uses the exact 55-character format. Higher versions are
accepted when their mandatory prefix is parseable; any extension remains
opaque and is preserved in traceparent for forwarding. No identifiers
are generated when parsing fails.
Source code in dataexcept/trace_context.py
trace_context_from_mapping ¶
Extract W3C trace context from a case-insensitive mapping-like carrier.
The mapping can represent HTTP headers, RPC metadata, broker properties or
protocol metadata such as MCP _meta. Invalid tracestate or
baggage values are dropped without invalidating a valid traceparent.
Source code in dataexcept/trace_context.py
HTTP request context¶
http_context ¶
Framework-neutral HTTP request context for DataExcept observability.
The adapter works with plain header mappings and route templates, so ASGI, WSGI, serverless and RPC gateways can use the same logic without becoming runtime dependencies of DataExcept.
HttpContext ¶
Request operation context plus optional W3C propagation context.
Source code in dataexcept/http_context.py
http_context_from_request ¶
http_context_from_request(method: str, *, route: str | None = None, headers: Mapping[str, object] | None = None, system: str | None = 'http', component: str | None = None, request_id_headers: Sequence[str] = _DEFAULT_REQUEST_ID_HEADERS, correlation_id_headers: Sequence[str] = _DEFAULT_CORRELATION_ID_HEADERS) -> HttpContext
Build request observability context from plain HTTP-style inputs.
route should be a low-cardinality route template such as
/users/{id}, never a raw request path. Request and correlation IDs are
read from configurable headers. W3C trace context is propagated when
present, but no trace or span identifiers are generated when it is absent.
Source code in dataexcept/http_context.py
Worker/task context¶
worker_context ¶
Framework-neutral task/worker context for DataExcept observability.
The adapter accepts plain task metadata so Celery, RQ, Arq, Dramatiq, custom workers and orchestration executors can share one dependency-free boundary model. Task arguments and payloads are intentionally out of scope.
WorkerContext ¶
Task operation context plus optional trace and retry metadata.
Source code in dataexcept/worker_context.py
worker_context_from_task ¶
worker_context_from_task(task_name: str, *, job_id: str | None = None, metadata: Mapping[str, object] | None = None, system: str | None = 'worker', component: str | None = None, correlation_id: str | None = None, attempt: int | None = None, job_id_keys: Sequence[str] = _DEFAULT_JOB_ID_KEYS, correlation_id_keys: Sequence[str] = _DEFAULT_CORRELATION_ID_KEYS) -> WorkerContext
Build worker observability context from plain task metadata.
task_name should be the stable registered task name, never arguments or
a rendered payload. Explicit job_id and correlation_id values take
precedence over metadata fallbacks. W3C trace context is propagated when
present and no identifiers are generated when it is absent.
Source code in dataexcept/worker_context.py
Workflow/orchestrator context¶
orchestrator_context ¶
Framework-neutral workflow/orchestrator observability context.
The adapter accepts plain workflow metadata so Airflow, Dagster, Prefect, Argo and custom schedulers can share the same dependency-free boundary model. Payloads and task arguments are intentionally excluded.
OrchestratorContext ¶
Workflow-step context plus optional trace and retry metadata.
Source code in dataexcept/orchestrator_context.py
orchestrator_context_from_step ¶
orchestrator_context_from_step(workflow: str, step: str, *, run_id: str | None = None, step_run_id: str | None = None, metadata: Mapping[str, object] | None = None, system: str | None = 'orchestrator', component: str | None = None, correlation_id: str | None = None, attempt: int | None = None) -> OrchestratorContext
Build observability context for one workflow/orchestrator step.
The operation name is the stable workflow:step pair. Run identifiers
remain correlation metadata and are never folded into the operation name.
Incoming W3C trace context is preserved when present.
Source code in dataexcept/orchestrator_context.py
Serverless invocation context¶
serverless_context ¶
Framework-neutral serverless invocation context for observability.
The adapter accepts plain invocation metadata so AWS Lambda, Azure Functions, Google Cloud Functions, OpenFaaS and custom function runtimes can share one dependency-free boundary model. Event payloads are intentionally excluded.
ServerlessContext ¶
Invocation operation context plus optional runtime metadata.
Source code in dataexcept/serverless_context.py
serverless_context_from_invocation ¶
serverless_context_from_invocation(function_name: str, *, invocation_id: str | None = None, metadata: Mapping[str, object] | None = None, system: str | None = 'serverless', component: str | None = None, correlation_id: str | None = None, cold_start: bool | None = None, runtime: str | None = None, invocation_id_keys: Sequence[str] = _DEFAULT_INVOCATION_ID_KEYS, correlation_id_keys: Sequence[str] = _DEFAULT_CORRELATION_ID_KEYS) -> ServerlessContext
Build observability context for one serverless function invocation.
function_name is the stable deployed function identity. Per-invocation request IDs stay correlation metadata and event payloads are never captured. Explicit invocation and correlation IDs take precedence over metadata fallbacks. Incoming W3C trace context is preserved when present.
Source code in dataexcept/serverless_context.py
Logging helpers¶
logging_helpers ¶
Helper functions for logging exceptions consistently.
log_exception ¶
log_exception(exc: Exception, logger: Optional[Logger] = None, level: int = logging.ERROR, context: Context | None = None, operation_context: OperationContext | None = None) -> None
Log exc at the given log level using logger.
If logger is None a module level logger is used.
context remains the free-form application context. operation_context
carries the stable request/job/tool-call identifiers shared with tracing and
error-tracker integrations.
DataExcept redacts what it renders, but a wrapped third-party exception
renders itself: an HTTP client's error may quote the credential-bearing URL
it was called with, and exc_info makes logging print that whole chain.
When the chain contains a URL the traceback is formatted and scrubbed here;
otherwise the structured exc_info path is used unchanged, so ordinary
exceptions keep the shape log aggregators expect.
Logging is fail-open: context conversion, traceback rendering or the logger itself may fail, but that failure is swallowed so observability can never replace the exception the caller was already handling.
Source code in dataexcept/logging_helpers.py
log_and_raise ¶
log_and_raise(logger: Optional[Logger] = None, level: int = logging.ERROR, context: Context | None = None, operation_context: OperationContext | None = None) -> Iterator[None]
Context manager that logs and re-raises exceptions preserving traceback.
Source code in dataexcept/logging_helpers.py
log_then_raise ¶
log_then_raise(exc: Exception, logger: Optional[Logger] = None, level: int = logging.ERROR, context: Context | None = None, operation_context: OperationContext | None = None) -> None
Log exc and immediately raise it.
This helper mirrors the pre-context-manager API for scenarios where adding a
with block would be too intrusive. Prefer :func:log_and_raise whenever
possible so tracebacks remain untouched.
Source code in dataexcept/logging_helpers.py
Command-line entry point¶
__main__ ¶
Command line interface for the DataExcept package.
main ¶
Entry point for the dataexcept command.