Exceptions¶
exceptions ¶
Classes¶
BoxlabError ¶
Bases: Exception
Base exception for all Boxlab-related errors.
This is the root exception class for the Boxlab library. All custom exceptions in Boxlab inherit from this class, making it easy to catch any Boxlab-specific error.
Each exception has an associated error code for programmatic error handling and a default message that can be overridden.
Attributes:
| Name | Type | Description |
|---|---|---|
default_message | str | Default error message for this exception type. |
code | int | Unique error code identifying this exception type. |
message | The actual error message for this instance. |
Example
Example
Initialize the exception.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
message | str | None | Custom error message. If None, uses default_message. | None |
Source code in boxlab/exceptions.py
RequiredModuleNotFoundError ¶
Bases: BoxlabError
Exception raised when a required module is not found.
This exception is raised when attempting to use functionality that requires optional dependencies (e.g., torch, torchvision, PIL) that are not installed.
Attributes:
| Name | Type | Description |
|---|---|---|
default_message | Template for the default error message. | |
code | int | Error code 2. |
module_name | Tuple of missing module names. |
Example
Example
Initialize the exception.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*module_name | str | One or more names of missing modules. | () |
message | str | None | Custom error message. If None, uses formatted default_message. | None |
Source code in boxlab/exceptions.py
DatasetError ¶
Bases: BoxlabError
Base exception for dataset-related errors.
This is the base class for all dataset operation errors. Catch this exception to handle any dataset-related issue.
Attributes:
| Name | Type | Description |
|---|---|---|
default_message | Default error message. | |
code | int | Error code 10. |
Example
Source code in boxlab/exceptions.py
DatasetNotFoundError ¶
Bases: DatasetError
Exception raised when a dataset is not found.
Raised when attempting to load or access a dataset that doesn't exist at the specified path.
Attributes:
| Name | Type | Description |
|---|---|---|
default_message | Template for the default error message. | |
code | int | Error code 11. |
path | The path where the dataset was expected. |
Example
Example
Initialize the exception.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path | str | The path where the dataset was expected. | required |
message | str | None | Custom error message. If None, uses formatted default_message. | None |
Source code in boxlab/exceptions.py
Functions¶
DatasetFormatError ¶
Bases: DatasetError
Exception raised for invalid dataset format.
Raised when a dataset file or structure doesn't match the expected format, or when the format is not recognized.
Attributes:
| Name | Type | Description |
|---|---|---|
default_message | Template for the default error message. | |
code | int | Error code 12. |
format | The format that caused the error. |
Example
Example
Initialize the exception.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
format | str | The format identifier that caused the error. | required |
message | str | None | Custom error message. If None, uses formatted default_message. | None |
Source code in boxlab/exceptions.py
Functions¶
DatasetLoadError ¶
Bases: DatasetError
Exception raised when dataset loading fails.
Raised when an error occurs during the dataset loading process, such as corrupted files, parsing errors, or I/O failures.
Attributes:
| Name | Type | Description |
|---|---|---|
default_message | Template for the default error message. | |
code | int | Error code 13. |
reason | Description of why loading failed. |
Example
Example
Initialize the exception.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
reason | str | Description of why loading failed. | required |
message | str | None | Custom error message. If None, uses formatted default_message. | None |
Source code in boxlab/exceptions.py
Functions¶
DatasetExportError ¶
Bases: DatasetError
Exception raised when dataset export fails.
Raised when an error occurs during dataset export, such as I/O failures, permission errors, or format conversion issues.
Attributes:
| Name | Type | Description |
|---|---|---|
default_message | Template for the default error message. | |
code | int | Error code 14. |
reason | Description of why export failed. |
Example
Example
Initialize the exception.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
reason | str | Description of why export failed. | required |
message | str | None | Custom error message. If None, uses formatted default_message. | None |
Source code in boxlab/exceptions.py
Functions¶
DatasetMergeError ¶
Bases: DatasetError
Exception raised when dataset merge fails.
Raised when an error occurs during dataset merging operations, such as incompatible datasets or merge conflicts.
Attributes:
| Name | Type | Description |
|---|---|---|
default_message | Template for the default error message. | |
code | int | Error code 15. |
reason | Description of why merge failed. |
Example
Example
Initialize the exception.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
reason | str | Description of why merge failed. | required |
message | str | None | Custom error message. If None, uses formatted default_message. | None |
Source code in boxlab/exceptions.py
Functions¶
CategoryConflictError ¶
Bases: DatasetError
Exception raised when category conflicts occur.
Raised during dataset merging when category names conflict and the conflict resolution strategy is set to 'error'.
Attributes:
| Name | Type | Description |
|---|---|---|
default_message | Template for the default error message. | |
code | int | Error code 16. |
category_name | The category name that caused the conflict. |
Example
Example
Initialize the exception.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
category_name | str | The category name that caused the conflict. | required |
message | str | None | Custom error message. If None, uses formatted default_message. | None |
Source code in boxlab/exceptions.py
Functions¶
ValidationError ¶
Bases: BoxlabError
Exception raised for validation errors.
Raised when data fails validation checks, such as invalid split ratios, malformed bounding boxes, or constraint violations.
Attributes:
| Name | Type | Description |
|---|---|---|
default_message | Template for the default error message. | |
code | int | Error code 20. |
reason | Description of what failed validation. |
Example
Example
Initialize the exception.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
reason | str | Description of what failed validation. | required |
message | str | None | Custom error message. If None, uses formatted default_message. | None |
Source code in boxlab/exceptions.py
Functions¶
options: show_root_heading: true show_source: true heading_level: 2 members_order: source show_signature_annotations: true separate_signature: true
Overview¶
BoxLab uses a hierarchical exception system for clear and specific error handling. All exceptions inherit from BoxlabError, making it easy to catch all BoxLab-specific errors or handle specific error types.
Each exception has:
- A unique error code for programmatic handling
- A default message template
- Additional context attributes relevant to the error type
Exception Hierarchy¶
BoxlabError (code: 1)
├── RequiredModuleNotFoundError (code: 2)
├── DatasetError (code: 10)
│ ├── DatasetNotFoundError (code: 11)
│ ├── DatasetFormatError (code: 12)
│ ├── DatasetLoadError (code: 13)
│ ├── DatasetExportError (code: 14)
│ ├── DatasetMergeError (code: 15)
│ └── CategoryConflictError (code: 16)
└── ValidationError (code: 20)
Error Codes¶
Error codes can be used for programmatic error handling:
| Code | Exception | Category |
|---|---|---|
| 1 | BoxlabError | Base |
| 2 | RequiredModuleNotFoundError | Dependencies |
| 10 | DatasetError | Dataset (base) |
| 11 | DatasetNotFoundError | Dataset I/O |
| 12 | DatasetFormatError | Dataset Format |
| 13 | DatasetLoadError | Dataset Loading |
| 14 | DatasetExportError | Dataset Export |
| 15 | DatasetMergeError | Dataset Merge |
| 16 | CategoryConflictError | Dataset Merge |
| 20 | ValidationError | Validation |
See Also¶
- Dataset Core - Core dataset functionality
- I/O Operations - Loading and exporting
- Types - Data structures and validation