atom/publish/
error.rs

1//! # Publishing Errors
2//!
3//! This module contains the error types for errors that might occur during publishing.
4use thiserror::Error;
5
6#[derive(Error, Debug)]
7/// The error representing a failure during publishing for any store implementation.
8pub enum PublishError {
9    /// A transparent wrapper for a [`GitError`].
10    #[error(transparent)]
11    Git(#[from] git::Error),
12}
13
14pub mod git {
15    //! # Git Publishing Errors
16    use std::path::PathBuf;
17
18    use gix::object;
19
20    use crate::store::git::Root;
21    /// An error representing a failure during publishing to a Git Ekala store.
22    #[derive(thiserror::Error, Debug)]
23    pub enum Error {
24        /// A transparent wrapper for a [`Box<gix::remote::find::existing::Error>`]
25        #[error(transparent)]
26        RemotNotFound(#[from] Box<gix::remote::find::existing::Error>),
27        /// A transparent wrapper for a [`Box<gix::revision::spec::parse::single::Error>`]
28        #[error(transparent)]
29        RevParseFailed(#[from] Box<gix::revision::spec::parse::single::Error>),
30        /// A transparent wrapper for a [`object::find::existing::with_conversion::Error`]
31        #[error(transparent)]
32        NoCommit(#[from] object::find::existing::with_conversion::Error),
33        /// A transparent wrapper for a [`object::commit::Error`]
34        #[error(transparent)]
35        NoTree(#[from] object::commit::Error),
36        /// A transparent wrapper for a [`object::find::existing::Error`]
37        #[error(transparent)]
38        NoObject(#[from] object::find::existing::Error),
39        /// A transparent wrapper for a [`gix::hasher::Error`]
40        #[error(transparent)]
41        Hash(#[from] gix::hash::hasher::Error),
42        /// A transparent wrapper for a [`object::write::Error`]
43        #[error(transparent)]
44        WriteFailed(#[from] object::write::Error),
45        /// A transparent wrapper for a [`gix::reference::edit::Error`]
46        #[error(transparent)]
47        RefUpdateFailed(#[from] gix::reference::edit::Error),
48        /// A transparent wrapper for a [`gix::revision::walk::Error`]
49        #[error(transparent)]
50        CalculatingRootFailed(#[from] gix::revision::walk::Error),
51        /// A transparent wrapper for a [`gix::traverse::commit::simple::Error`]
52        #[error(transparent)]
53        RootConversionFailed(#[from] gix::traverse::commit::simple::Error),
54        /// A transparent wrapper for a [`std::io::Error`]
55        #[error(transparent)]
56        Io(#[from] std::io::Error),
57        /// A transparent wrapper for a [`tokio::task::JoinError`]
58        #[error(transparent)]
59        JoinFailed(#[from] tokio::task::JoinError),
60        /// The reported root & the atom root are inconsistent.
61        #[error("Atom does not derive from the initialized history")]
62        InconsistentRoot {
63            /// The root according to the remote we are publishing to.
64            remote: Root,
65            /// The root of history for the source from which the atom is derived.
66            atom: Root,
67        },
68        /// The remote is not initialized as an Ekala store.
69        #[error("Remote is not initialized")]
70        NotInitialized,
71        /// The Atom manifest is invalid, and this Atom will be ignored.
72        #[error("Ignoring invalid Atom manifest")]
73        Invalid(#[source] crate::manifest::AtomError, Box<PathBuf>),
74        /// The path given does not point to an Atom.
75        #[error("The given path does not point to an Atom")]
76        NotAnAtom(PathBuf),
77        /// An atom exist's at the repo root.
78        #[error("Atoms cannot exist at the repo root")]
79        NoRootAtom,
80        /// Failed to sync a least one Atom to the remote.
81        #[error("Failed to sync some Atoms to the remote")]
82        SomePushFailed,
83        /// Some Atoms failed to publish
84        #[error("Failed to published some of the specified Atoms")]
85        Failed,
86        /// A transparent wrapper for a [`crate::store::git::Error`]
87        #[error(transparent)]
88        StoreError(#[from] Box<crate::store::git::Error>),
89        /// No Atoms found under the given directory.
90        #[error("Failed to find any Atoms under the current directory")]
91        NotFound,
92        /// Atoms with the same Unicode ID were found in the given revision.
93        #[error("Duplicate Atoms detected in the given revision, refusing to publish")]
94        Duplicates,
95    }
96
97    impl Error {
98        const INCONSISTENT_ROOT_SUGGESTION: &str =
99            "You may need to reinitalize the remote if the issue persists";
100
101        /// Warn the user about specific error conditions encountered during publishing.
102        pub fn warn(&self) {
103            match self {
104                Error::InconsistentRoot { remote, atom } => {
105                    tracing::warn!(
106                        message = %self,
107                        atom_root = %**atom,
108                        remote_root = %**remote,
109                        suggest = Error::INCONSISTENT_ROOT_SUGGESTION
110                    );
111                },
112                Error::Invalid(e, path) => {
113                    tracing::warn!(message = %self, path = %path.display(), message = format!("\n{}", e));
114                },
115                Error::NotAnAtom(path) => {
116                    tracing::warn!(message = %self, path = %path.display());
117                },
118                Error::Failed => (),
119                _ => tracing::warn!(message = %self),
120            }
121        }
122    }
123}