Skip to content

comicbox.exceptions

Exceptions for comicbox.

Every operational error comicbox raises on a public path derives from :class:ComicboxError, so library consumers can write except ComicboxError without also swallowing unrelated programming errors (ValueError, KeyError, …) from their own code.

This module is a leaf: it must not import anything from comicbox, so any module (including the format packages and the box mixins) can import it without load-order concerns. The write/online modules re-export their exceptions from here under their historical import paths.

ArchiveError

Bases: ComicboxError

An archive could not be opened or read.

Source code in comicbox/exceptions.py
36
37
class ArchiveError(ComicboxError):
    """An archive could not be opened or read."""

ArchiveWriteError

Bases: ArchiveError

An archive could not be written, repacked, or renamed.

Source code in comicbox/exceptions.py
40
41
class ArchiveWriteError(ArchiveError):
    """An archive could not be written, repacked, or renamed."""

ComicNotFoundError

Bases: ComicboxError, FileNotFoundError

A comic path names nothing on disk.

Also a FileNotFoundError, which is what this raised before this class existed, so callers catching that keep working.

Source code in comicbox/exceptions.py
111
112
113
114
115
116
117
class ComicNotFoundError(ComicboxError, FileNotFoundError):
    """
    A comic path names nothing on disk.

    Also a FileNotFoundError, which is what this raised before this class
    existed, so callers catching that keep working.
    """

ComicboxError

Bases: Exception

Base class for all operational errors comicbox raises.

Source code in comicbox/exceptions.py
28
29
class ComicboxError(Exception):
    """Base class for all operational errors comicbox raises."""

ConfigurationError

Bases: ComicboxError, ValueError

A config file, env var, or argument holds a value comicbox rejects.

Also a ValueError, which is what these sites raised before this class existed, so callers catching that keep working.

Source code in comicbox/exceptions.py
102
103
104
105
106
107
108
class ConfigurationError(ComicboxError, ValueError):
    """
    A config file, env var, or argument holds a value comicbox rejects.

    Also a ValueError, which is what these sites raised before this class
    existed, so callers catching that keep working.
    """

DestinationOccupiedError

Bases: ArchiveWriteError

A write’s destination path is held by another file or writer.

kind says which collision: "convert" – the CBZ this archive would repack to already exists (or another archive in the same batch claims it, in which case occupant names it); "rename" – the predicted filename is taken; "inflight" – another writer in this process holds the destination right now (transient; retry later).

Source code in comicbox/exceptions.py
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
class DestinationOccupiedError(ArchiveWriteError):
    """
    A write's destination path is held by another file or writer.

    ``kind`` says which collision: ``"convert"`` -- the CBZ this archive
    would repack to already exists (or another archive in the same batch
    claims it, in which case ``occupant`` names it); ``"rename"`` -- the
    predicted filename is taken; ``"inflight"`` -- another writer in this
    process holds the destination right now (transient; retry later).
    """

    def __init__(
        self,
        source: Path,
        destination: Path,
        kind: DestinationKind,
        occupant: Path | None = None,
    ) -> None:
        """Record the two paths, the collision kind, and any rival source."""
        self.source = source
        self.destination = destination
        self.kind = kind
        self.occupant = occupant
        super().__init__(self._message())

    def _message(self) -> str:
        """Render the frozen message text for this collision kind."""
        if self.kind == "inflight":
            return f"{self.destination} is already being written by another archive."
        if self.occupant is not None:
            return f"{self.destination} is also the destination of {self.occupant}."
        return f"{self.destination} already exists."

    @override
    def __reduce__(self) -> tuple:
        """
        Rebuild with the real signature when crossing a process boundary.

        Python unpickles an exception as ``cls(*self.args)``, which here
        is ``cls(message)`` -- a TypeError that would replace the real
        error with a bogus one on the far side. WriteResult.error is a
        public field, so keep it picklable.
        """
        return (type(self), (self.source, self.destination, self.kind, self.occupant))

__init__(source, destination, kind, occupant=None)

Record the two paths, the collision kind, and any rival source.

Source code in comicbox/exceptions.py
67
68
69
70
71
72
73
74
75
76
77
78
79
def __init__(
    self,
    source: Path,
    destination: Path,
    kind: DestinationKind,
    occupant: Path | None = None,
) -> None:
    """Record the two paths, the collision kind, and any rival source."""
    self.source = source
    self.destination = destination
    self.kind = kind
    self.occupant = occupant
    super().__init__(self._message())

__reduce__()

Rebuild with the real signature when crossing a process boundary.

Python unpickles an exception as cls(*self.args), which here is cls(message) – a TypeError that would replace the real error with a bogus one on the far side. WriteResult.error is a public field, so keep it picklable.

Source code in comicbox/exceptions.py
89
90
91
92
93
94
95
96
97
98
99
@override
def __reduce__(self) -> tuple:
    """
    Rebuild with the real signature when crossing a process boundary.

    Python unpickles an exception as ``cls(*self.args)``, which here
    is ``cls(message)`` -- a TypeError that would replace the real
    error with a bogus one on the far side. WriteResult.error is a
    public field, so keep it picklable.
    """
    return (type(self), (self.source, self.destination, self.kind, self.occupant))

ExportError

Bases: ComicboxError

A metadata file export failed its preconditions.

Source code in comicbox/exceptions.py
124
125
class ExportError(ComicboxError):
    """A metadata file export failed its preconditions."""

MetadataError

Bases: ComicboxError

Metadata could not be loaded or routed through the source pipeline.

Source code in comicbox/exceptions.py
120
121
class MetadataError(ComicboxError):
    """Metadata could not be loaded or routed through the source pipeline."""

OnlineConfigurationError

Bases: ComicboxError

Raised when OnlineSession inputs are inconsistent or incomplete.

Source code in comicbox/exceptions.py
132
133
class OnlineConfigurationError(ComicboxError):
    """Raised when OnlineSession inputs are inconsistent or incomplete."""

OnlineLookupAbortedError

Bases: ComicboxError

Raised when the selector callback returns (‘abort’, None).

Source code in comicbox/exceptions.py
136
137
class OnlineLookupAbortedError(ComicboxError):
    """Raised when the selector callback returns ('abort', None)."""

ReadingListError

Bases: ComicboxError

A reading list could not be read, converted, combined or written.

Source code in comicbox/exceptions.py
140
141
class ReadingListError(ComicboxError):
    """A reading list could not be read, converted, combined or written."""

ReadingListFetchError

Bases: ReadingListError

A reading list could not be fetched.

A network failure, an HTTP error, a refused URL, a download over the size cap, or a missing credential. A cancel, or a spent quota, raises OnlineLookupAbortedError instead, as tagging does.

Source code in comicbox/exceptions.py
157
158
159
160
161
162
163
164
class ReadingListFetchError(ReadingListError):
    """
    A reading list could not be fetched.

    A network failure, an HTTP error, a refused URL, a download over the
    size cap, or a missing credential. A cancel, or a spent quota, raises
    ``OnlineLookupAbortedError`` instead, as tagging does.
    """

ReadingListFormatError

Bases: ReadingListError

A document is not a reading list in any format comicbox reads.

Source code in comicbox/exceptions.py
144
145
class ReadingListFormatError(ReadingListError):
    """A document is not a reading list in any format comicbox reads."""

SmartListError

Bases: ReadingListFormatError

A ComicRack smart list.

Its <Matchers> are rules that select comics from a library, not a list of issues, so there is nothing to read.

Source code in comicbox/exceptions.py
148
149
150
151
152
153
154
class SmartListError(ReadingListFormatError):
    """
    A ComicRack smart list.

    Its ``<Matchers>`` are rules that select comics from a library, not a
    list of issues, so there is nothing to read.
    """

UnparsedTagFileError

Bases: ArchiveWriteError

A keep write refused: a tag file the comic carries did not parse.

Source code in comicbox/exceptions.py
44
45
class UnparsedTagFileError(ArchiveWriteError):
    """A keep write refused: a tag file the comic carries did not parse."""

UnsafePdfAttachmentError

Bases: ArchiveWriteError

A PDF write refused: replacing its tag files would harm another attachment.

Source code in comicbox/exceptions.py
52
53
class UnsafePdfAttachmentError(ArchiveWriteError):
    """A PDF write refused: replacing its tag files would harm another attachment."""

UnsupportedArchiveTypeError

Bases: ComicboxError

Unsupported Archive Type.

Source code in comicbox/exceptions.py
32
33
class UnsupportedArchiveTypeError(ComicboxError):
    """Unsupported Archive Type."""

UnwritableFormatError

Bases: ArchiveWriteError

A write refused: -w names no format this archive can hold.

Source code in comicbox/exceptions.py
48
49
class UnwritableFormatError(ArchiveWriteError):
    """A write refused: -w names no format this archive can hold."""

WriteValidationError

Bases: ComicboxError

Raised when write_metadata inputs are inconsistent or invalid.

Source code in comicbox/exceptions.py
128
129
class WriteValidationError(ComicboxError):
    """Raised when write_metadata inputs are inconsistent or invalid."""