better error chaining

This commit is contained in:
Trevor Bentley
2025-01-14 00:00:01 +01:00
parent b5c7f89959
commit 55789ff98e
3 changed files with 67 additions and 4 deletions
Generated
+50
View File
@@ -366,6 +366,18 @@ dependencies = [
"regex",
]
[[package]]
name = "filetime"
version = "0.2.19"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4e884668cd0c7480504233e951174ddc3b382f7c2666e3b7310b5c4e7b0c37f9"
dependencies = [
"cfg-if",
"libc",
"redox_syscall",
"windows-sys",
]
[[package]]
name = "flate2"
version = "1.0.25"
@@ -436,6 +448,12 @@ dependencies = [
"url",
]
[[package]]
name = "glob"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d2fabcfbdc87f4758337ca535fb41a6d701b65693ce38287d856d1674551ec9b"
[[package]]
name = "globset"
version = "0.4.10"
@@ -582,12 +600,15 @@ version = "0.5.1"
dependencies = [
"chrono",
"clap",
"flate2",
"git2",
"glob",
"open",
"pulldown-cmark",
"rayon",
"serde",
"syntect",
"tar",
"tera",
"toml",
]
@@ -1053,6 +1074,15 @@ dependencies = [
"num_cpus",
]
[[package]]
name = "redox_syscall"
version = "0.2.16"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fb5a58c1855b4b6819d59012155603f0b22ad30cad752600aadfcb695265519a"
dependencies = [
"bitflags",
]
[[package]]
name = "regex"
version = "1.7.0"
@@ -1215,6 +1245,17 @@ dependencies = [
"yaml-rust",
]
[[package]]
name = "tar"
version = "0.4.38"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4b55807c0344e1e6c04d7c965f5289c39a8d94ae23ed5c0b57aabac549f871c6"
dependencies = [
"filetime",
"libc",
"xattr",
]
[[package]]
name = "tera"
version = "1.17.1"
@@ -1632,6 +1673,15 @@ version = "0.42.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f40009d85759725a34da6d89a94e63d7bdc50a862acf0dbc7c8e488f1edcb6f5"
[[package]]
name = "xattr"
version = "0.2.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6d1526bbe5aaeb5eb06885f4d987bcdfa5e23187055de9b83fe00156a821fabc"
dependencies = [
"libc",
]
[[package]]
name = "xml-rs"
version = "0.8.4"
+5
View File
@@ -21,6 +21,7 @@ highlight = ["syntect/default-fancy"]
chrono = { version = "0.4.23", features=["clock"] }
clap = { version="4.0.32", features=["derive"] }
git2 = "0.15.0"
glob = "0.3.1"
open = "3.2.0"
pulldown-cmark = { version = "0.9.2", optional = true }
rayon = "1.6.1"
@@ -32,3 +33,7 @@ toml = "0.5.10"
# For SSH passphrase support:
#pinentry = "0.5.0"
#secrecy = "0.8.0"
[dev-dependencies]
flate2 = "1.0.25"
tar = "0.4.38"
+12 -4
View File
@@ -20,6 +20,8 @@
* You should have received a copy of the GNU General Public License
* along with Itsy-Gitsy. If not, see <http://www.gnu.org/licenses/>.
*/
use glob::glob;
use std::error::Error as StdError;
use std::path::Path;
use std::path::PathBuf;
use std::sync::atomic::AtomicUsize;
@@ -83,6 +85,7 @@ pub enum GitsyErrorKind {
Settings,
Template,
Git,
Filesystem,
}
#[derive(Default)]
@@ -126,9 +129,14 @@ impl std::fmt::Display for GitsyError {
GitsyErrorKind::Git => write!(f, "gitsy error (git)")?,
GitsyErrorKind::Settings => write!(f, "gitsy error (settings)")?,
GitsyErrorKind::Template => write!(f, "gitsy error (template)")?,
_ => write!(f, "gitsy error (unknown)")?,
GitsyErrorKind::Filesystem => write!(f, "gitsy error (filesystem)")?,
GitsyErrorKind::Unknown => write!(f, "gitsy error (unknown)")?,
}
write!(f, ": {}", self.msg.as_deref().unwrap_or_default())
write!(f, ": {}", self.msg.as_deref().unwrap_or_default())?;
if let Some(src) = &self.source {
write!(f, " ({})", src)?;
}
Ok(())
}
}
impl std::fmt::Debug for GitsyError {
@@ -137,8 +145,8 @@ impl std::fmt::Debug for GitsyError {
}
}
impl std::error::Error for GitsyError {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
self.source.as_deref()
fn source(&self) -> Option<&(dyn StdError + 'static)> {
self.source.as_ref().map(|c| &**c as &(dyn StdError + 'static))
}
}
impl From<git2::Error> for GitsyError {