Error handling
file-keeper provides a comprehensive set of exceptions to help you handle errors gracefully. This page documents the available exceptions and provides guidance on how to handle them.
General exception hierarchy
All exceptions in file-keeper inherit from the base
FilesError
exception. This allows you to catch
all file-keeper related errors with a single except
block. More specific
exceptions are derived from FilesError to
provide more detailed error information.
Note
file-keeper's exceptions can be imported from file_keeper.core.exceptions
from file_keeper.core.exceptions import FilesError
try:
...
except FilesError:
...
As a shortcut, they can be accessed from the exc
object available at the root
of file-keeper module
from file_keeper import exc
try:
...
except exc.FilesError:
...
Example error handling
from file_keeper import make_storage, make_upload, exc
try:
storage = make_storage("my_storage", {"type": "file_keeper:fs", "path": "/nonexistent/path"})
except exc.InvalidStorageConfigurationError as e:
print(f"Error configuring storage: {e}")
upload = make_upload(b"Hello, file-keeper!")
try:
storage.upload("my_file.txt", upload)
except exc.ExistingFileError as e:
print(f"File already exists: {e}")
exc
Exception definitions for the extension.
Hierarchy:
- Exception
ContentError(storage, msg)
ExistingFileError(storage, location)
ExtrasError(problem)
FilesError
Bases: Exception
Base error for catch-all scenario.
InvalidStorageConfigurationError(adapter_or_storage, problem)
LargeUploadError(actual_size, max_size)
LocationError(storage, location)
LocationTransformerError(transformer)
MissingExtrasError(key)
MissingFileError(storage, location)
MissingStorageConfigurationError(adapter_or_storage, option)
MultipartUploadError
Bases: UploadError
Error related to multipart upload process.
PermissionError(storage, operation, problem)
ResumableUploadError
Bases: UploadError
Error related to resumable upload process.
StorageDataError(problem)
StorageError
Bases: FilesError
Error related to storage.
UnknownAdapterError(adapter)
UnknownStorageError(storage)
UnsupportedOperationError(operation, storage)
UploadError
Bases: StorageError
Error related to file upload process.