Skip to content

mongrator.exceptions

mongrator.exceptions

MigratorError

Bases: Exception

Base class for all mongrator errors.

Source code in src/mongrator/exceptions.py
1
2
class MigratorError(Exception):
    """Base class for all mongrator errors."""

ConfigurationError

Bases: MigratorError

Invalid or missing configuration.

Source code in src/mongrator/exceptions.py
5
6
class ConfigurationError(MigratorError):
    """Invalid or missing configuration."""

ChecksumMismatchError

Bases: MigratorError

Applied migration file has been modified since it was run.

Source code in src/mongrator/exceptions.py
 9
10
11
12
13
14
15
16
17
18
19
20
class ChecksumMismatchError(MigratorError):
    """Applied migration file has been modified since it was run."""

    def __init__(self, migration_id: str, expected: str, actual: str) -> None:
        self.migration_id = migration_id
        self.expected = expected
        self.actual = actual
        super().__init__(
            f"Checksum mismatch for '{migration_id}': "
            f"expected {expected!r}, got {actual!r}. "
            "The migration file has been modified after being applied."
        )

DuplicateMigrationIdError

Bases: MigratorError

Two migration files share the same ID.

Source code in src/mongrator/exceptions.py
23
24
25
26
27
28
class DuplicateMigrationIdError(MigratorError):
    """Two migration files share the same ID."""

    def __init__(self, migration_id: str) -> None:
        self.migration_id = migration_id
        super().__init__(f"Duplicate migration ID: '{migration_id}'")

MigrationImportError

Bases: MigratorError

A migration file could not be imported.

Source code in src/mongrator/exceptions.py
31
32
33
34
35
36
37
class MigrationImportError(MigratorError):
    """A migration file could not be imported."""

    def __init__(self, path: str, cause: Exception) -> None:
        self.path = path
        self.cause = cause
        super().__init__(f"Failed to import migration '{path}': {cause}")

InvalidMigrationFileError

Bases: MigratorError

A migration file is missing required callables or has an invalid structure.

Source code in src/mongrator/exceptions.py
40
41
42
43
44
45
46
class InvalidMigrationFileError(MigratorError):
    """A migration file is missing required callables or has an invalid structure."""

    def __init__(self, path: str, reason: str) -> None:
        self.path = path
        self.reason = reason
        super().__init__(f"Invalid migration file '{path}': {reason}")

NoDownMethodError

Bases: MigratorError

A migration has no rollback path.

Source code in src/mongrator/exceptions.py
49
50
51
52
53
54
55
56
57
class NoDownMethodError(MigratorError):
    """A migration has no rollback path."""

    def __init__(self, migration_id: str) -> None:
        self.migration_id = migration_id
        super().__init__(
            f"Migration '{migration_id}' has no rollback path. "
            "Define a down() function or use ops.* helpers that support auto-rollback."
        )

MigrationNotFoundError

Bases: MigratorError

A referenced migration ID does not exist.

Source code in src/mongrator/exceptions.py
60
61
62
63
64
65
class MigrationNotFoundError(MigratorError):
    """A referenced migration ID does not exist."""

    def __init__(self, migration_id: str) -> None:
        self.migration_id = migration_id
        super().__init__(f"Migration not found: '{migration_id}'")

ReservedMigrationIdError

Bases: MigratorError

A migration file uses a reserved internal ID.

Source code in src/mongrator/exceptions.py
68
69
70
71
72
73
74
75
class ReservedMigrationIdError(MigratorError):
    """A migration file uses a reserved internal ID."""

    def __init__(self, migration_id: str) -> None:
        self.migration_id = migration_id
        super().__init__(
            f"Migration ID '{migration_id}' is reserved for internal use. Please rename the migration file."
        )

MigrationLockError

Bases: MigratorError

Could not acquire the migration lock.

Source code in src/mongrator/exceptions.py
78
79
80
81
82
83
84
85
86
class MigrationLockError(MigratorError):
    """Could not acquire the migration lock."""

    def __init__(self) -> None:
        super().__init__(
            "Could not acquire migration lock. "
            "Another migration may be in progress. "
            "If this is stale, the lock will expire automatically."
        )

TransactionNotSupportedError

Bases: MigratorError

The MongoDB server does not support multi-document transactions.

Transactions require either a replica set or a sharded cluster (mongos). Standalone servers do not support them.

Source code in src/mongrator/exceptions.py
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
class TransactionNotSupportedError(MigratorError):
    """The MongoDB server does not support multi-document transactions.

    Transactions require either a replica set or a sharded cluster (mongos).
    Standalone servers do not support them.
    """

    def __init__(self) -> None:
        super().__init__(
            "Transactions require a MongoDB replica set or sharded cluster. "
            "The connected server does not support transactions. "
            "Run without --transactional or connect to a replica set or sharded cluster."
        )