Skip to content

EffectCraft: An open-source motion graphics and compositing tool written by scratch in pure Rust

Never crash: project crate without expect()

Brandon Thomas587d4803fe18
diff --git a/clippy.toml b/clippy.toml
new file mode 100644
index 000000000..4b6c79f55
--- /dev/null
+++ b/clippy.toml
@@ -0,0 +1,4 @@
+allow-unwrap-in-tests = true
+allow-expect-in-tests = true
+allow-panic-in-tests = true
+allow-indexing-slicing-in-tests = true
diff --git a/crates/engine/src/commands/track.rs b/crates/engine/src/commands/track.rs
index 928bf63b8..77cb74946 100644
--- a/crates/engine/src/commands/track.rs
+++ b/crates/engine/src/commands/track.rs
@@ -214,7 +214,7 @@ fn create(s: &mut Session, p: &V, cmd: &str) -> Result<V> {
let mut ids = Ids(&mut next);
let g = tracking::tracker(&mut ids, &name, st, &pts);
let uid = g.uid;
- l.motion_trackers_mut(&mut ids).children.push(g.into());
+ l.motion_trackers_mut(&mut ids).ok_or_else(|| bad(cmd, "the layer has no Motion Trackers group"))?.children.push(g.into());
proj.next_id = next;
state.current_track = Some((lid, uid));
state.selected_layers = vec![lid];
diff --git a/crates/project/src/lib.rs b/crates/project/src/lib.rs
index 5e32c7a42..429ba7ef3 100644
--- a/crates/project/src/lib.rs
+++ b/crates/project/src/lib.rs
@@ -4,6 +4,8 @@
//! ([`props`]). Compositions sit behind `Arc` so undo snapshots share everything that did not
//! change.
+#![deny(clippy::unwrap_used, clippy::expect_used, clippy::panic, clippy::unimplemented, clippy::todo, clippy::unreachable)]
+
pub mod build;
pub mod essential;
pub mod props;
diff --git a/crates/project/src/tracking.rs b/crates/project/src/tracking.rs
index 5e7f8f1d9..cc3447938 100644
--- a/crates/project/src/tracking.rs
+++ b/crates/project/src/tracking.rs
@@ -235,11 +235,11 @@ impl Layer {
self.trackers().find(|(g, _)| g.uid == uid)
}
/// The Motion Trackers group, created (first in the layer's tree, like AE) when missing.
- pub fn motion_trackers_mut(&mut self, ids: &mut Ids) -> &mut PropGroup {
+ pub fn motion_trackers_mut(&mut self, ids: &mut Ids) -> Option<&mut PropGroup> {
if self.props.sub(MOTION_TRACKERS).is_none() {
self.props.children.insert(0, motion_trackers(ids).into());
}
- self.props.sub_mut(MOTION_TRACKERS).expect("motion trackers group")
+ self.props.sub_mut(MOTION_TRACKERS)
}
}