Skip to content

Commit e560403

Browse files
committed
vfs: Use snafu instead of thiserror
1 parent 576e549 commit e560403

File tree

3 files changed

+24
-23
lines changed

3 files changed

+24
-23
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/vfs/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ edition.workspace = true
77

88
[dependencies]
99
indextree.workspace = true
10-
thiserror.workspace = true
10+
snafu.workspace = true
1111

1212
[lints]
1313
workspace = true

crates/vfs/src/tree/mod.rs

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use std::collections::HashMap;
99
use std::vec;
1010

1111
use indextree::{Arena, Descendants, NodeId};
12-
use thiserror::Error;
12+
use snafu::Snafu;
1313

1414
use crate::path;
1515

@@ -113,7 +113,9 @@ impl<T: BlitFile> Tree<T> {
113113
fn add_child_to_node(&mut self, node_id: NodeId, parent: &str) -> Result<(), Error> {
114114
let node = self.arena.get(node_id).unwrap();
115115
let Some(parent_node) = self.map.get(parent) else {
116-
return Err(Error::MissingParent(parent.to_owned()));
116+
return Err(Error::MissingParent {
117+
parent: parent.to_owned(),
118+
});
117119
};
118120

119121
let others = parent_node
@@ -128,22 +130,17 @@ impl<T: BlitFile> Tree<T> {
128130
})
129131
.collect::<Vec<_>>();
130132
if !others.is_empty() {
133+
let e = Error::Duplicate {
134+
node_path: node.get().path.clone(),
135+
node_id: node.get().id.clone(),
136+
other_id: others.first().unwrap().id.clone(),
137+
};
138+
131139
// TODO: Reenable
132-
// Err(Error::Duplicate(
133-
// node.get().path(),
134-
// node.get().id(),
135-
// others.first().unwrap().id(),
136-
// ))
140+
// return Err(e)
137141

138142
// Report duplicate and skip for now
139-
eprintln!(
140-
"error: {}",
141-
Error::Duplicate(
142-
node.get().path.clone(),
143-
node.get().id.clone(),
144-
others.first().unwrap().id.clone()
145-
)
146-
);
143+
eprintln!("error: {e}");
147144
} else {
148145
parent_node.append(node_id, &mut self.arena);
149146
}
@@ -253,11 +250,15 @@ impl<'a, T: BlitFile> Iterator for TreeIterator<'a, T> {
253250
}
254251
}
255252

256-
#[derive(Debug, Error)]
253+
#[derive(Debug, Snafu)]
257254
pub enum Error {
258-
#[error("missing parent: {0}")]
259-
MissingParent(String),
260-
261-
#[error("duplicate entry: {0} {1} attempts to overwrite {2}")]
262-
Duplicate(String, String, String),
255+
#[snafu(display("missing parent: {parent}"))]
256+
MissingParent { parent: String },
257+
258+
#[snafu(display("duplicate entry: {node_path} {node_id} attempts to overwrite {other_id}"))]
259+
Duplicate {
260+
node_path: String,
261+
node_id: String,
262+
other_id: String,
263+
},
263264
}

0 commit comments

Comments
 (0)