mongodb_migrator/
error.rs

1use std::collections::BTreeMap;
2
3use mongodb::error::Error as MongoDbError;
4use thiserror::Error;
5
6use crate::migration_record::MigrationRecord;
7
8#[derive(Error, Debug)]
9pub enum MigrationExecution {
10    #[error("Failed to create an initial record document for the migration which will be executed - {migration_id}
11	    record attempted to serialize: {migration_record:?}
12	    the migration: {migration_id}, and following it: {next_not_executed_migrations_ids:?} weren't executed")]
13    InitialMigrationRecord {
14        migration_id: String,
15        migration_record: MigrationRecord,
16        next_not_executed_migrations_ids: Vec<String>,
17        additional_info: bson::ser::Error,
18    },
19    #[error("Failed to write an initial record document for the migration which will be executed - {migration_id}
20	    the migration: {migration_id}, and following it: {next_not_executed_migrations_ids:?} weren't executed
21	    additional_info: {additional_info}")]
22    InProgressStatusNotSaved {
23        migration_id: String,
24        next_not_executed_migrations_ids: Vec<String>,
25        additional_info: MongoDbError,
26    },
27    #[error("Migration - {migration_id} has finished with the status: {migration_status}
28	    but the migration_record attempted to be writted as a migration result into migrations collections
29	    wasn't successfully serialized: {migration_record:?}, this is why it hasn't written
30	    due to inconsistency, following it migrations: {next_not_executed_migrations_ids:?} weren't executed")]
31    FinishedButNotSavedDueToSerialization {
32        migration_id: String,
33        migration_status: String,
34        migration_record: MigrationRecord,
35        next_not_executed_migrations_ids: Vec<String>,
36        additional_info: bson::ser::Error,
37    },
38    #[error("Failed to write the migration record document for the migration - {migration_id} with its result
39	    that migration was completed with the status: {migration_status}
40	    due to inconsistency, following it migrations: {next_not_executed_migrations_ids:?} weren't executed
41	    additional_info: {additional_info}")]
42    FinishedButNotSavedDueMongoError {
43        migration_id: String,
44        migration_status: String,
45        additional_info: MongoDbError,
46        next_not_executed_migrations_ids: Vec<String>,
47    },
48    #[error(
49        "Migration wasn't completed successfully - {migration_id}
50	 due to that, following it migrations: {next_not_executed_migrations_ids:?} weren't executed"
51    )]
52    FinishedAndSavedAsFail {
53        migration_id: String,
54        next_not_executed_migrations_ids: Vec<String>,
55    },
56    #[error(
57        "Migrations weren't executed since there are several migrations with duplicated ids(id, indices vec):
58	 {duplicates:?}"
59    )]
60    PassedMigrationsWithDuplicatedIds {
61        duplicates: BTreeMap<String, Vec<usize>>,
62    },
63    #[error("Single migration for execution wasn't found in migrations vec: {migration_id:?}")]
64    MigrationFromVecNotFound { migration_id: String },
65}