FilmCraft: An open-source, nonlinear video editor written by scratch in pure Rust
render, gpu, cli: never crash — no expect/unreachable, deny the panicking lints
Brandon Thomas5628fc55bc3c
diff --git a/apps/filmcraft-cli/src/args.rs b/apps/filmcraft-cli/src/args.rsindex bc65d419b..bac68febb 100644--- a/apps/filmcraft-cli/src/args.rs+++ b/apps/filmcraft-cli/src/args.rs@@ -88,7 +88,9 @@ fn insert_dotted(m: &mut Map<String, Value>, key: &str, v: Value) {if !e.is_object() {*e = Value::Object(Map::new());}- insert_dotted(e.as_object_mut().expect("object"), tail, v);+ if let Value::Object(child) = e {+ insert_dotted(child, tail, v);+ }}}}diff --git a/apps/filmcraft-cli/src/main.rs b/apps/filmcraft-cli/src/main.rsindex 36dcd7baf..1ad2f74f6 100644--- a/apps/filmcraft-cli/src/main.rs+++ b/apps/filmcraft-cli/src/main.rs@@ -2,6 +2,8 @@//!//! Run `filmcraft-cli help` for the full reference (also in docs/agents.md).+#![cfg_attr(not(test), deny(clippy::unwrap_used, clippy::expect_used, clippy::panic, clippy::unimplemented, clippy::todo, clippy::unreachable))]+mod args;mod probe;@@ -339,7 +341,7 @@ async fn main() {if a.opt("--bridge").is_some() {usage("render is headless; with --bridge use the MCP `render_frame` tool or `exec` ui commands");}- let Backend::Local(mut s) = Backend::open(&a) else { unreachable!() };+ let Backend::Local(mut s) = Backend::open(&a) else { usage("render is headless") };let secs: f64 = a.opt("--seconds").and_then(|v| v.parse().ok()).unwrap_or(0.0);let scale: f32 = a.opt("--scale").and_then(|v| v.parse().ok()).unwrap_or(1.0);let out = a.opt("--out").unwrap_or("frame.png");@@ -356,7 +358,7 @@ async fn main() {Some(addr) => filmcraft_automation::FilmcraftMcp::bridge(addr).unwrap_or_else(|e| fail(e)),None => match Backend::open(&a) {Backend::Local(s) => filmcraft_automation::FilmcraftMcp::headless(*s),- Backend::Bridge(_) => unreachable!(),+ Backend::Bridge(_) => usage("mcp: use --bridge ADDR to drive a running app"),},};if let Err(e) = server.serve_stdio().await {diff --git a/crates/gpu/src/lib.rs b/crates/gpu/src/lib.rsindex 72233d571..c9ba2ce9f 100644--- a/crates/gpu/src/lib.rs+++ b/crates/gpu/src/lib.rs@@ -13,6 +13,8 @@//!//! The CPU plan executor (`filmcraft_render::plan::execute_cpu`) is the oracle; tests compare.+#![cfg_attr(not(test), deny(clippy::unwrap_used, clippy::expect_used, clippy::panic, clippy::unimplemented, clippy::todo, clippy::unreachable))]+use std::collections::HashMap;use std::sync::Arc;@@ -279,9 +281,9 @@ impl GpuCompositor {h: u32,format: wgpu::TextureFormat,extra: wgpu::TextureUsages,- ) {- if slot.as_ref().is_some_and(|s| s.2 == (w, h)) {- return;+ ) -> wgpu::TextureView {+ if let Some(s) = slot.as_ref().filter(|s| s.2 == (w, h)) {+ return s.1.clone();}let t = device.create_texture(&wgpu::TextureDescriptor {label: Some("filmcraft-target"),@@ -294,7 +296,8 @@ impl GpuCompositor {view_formats: &[],});let v = t.create_view(&Default::default());- *slot = Some((t, v, (w, h)));+ *slot = Some((t, v.clone(), (w, h)));+ v}fn plane_texture(&mut self, w: u32, h: u32, format: wgpu::TextureFormat, bytes: &[u8], bpp: u32) -> wgpu::TextureView {@@ -443,13 +446,13 @@ impl GpuCompositor {}/// Composite a plan; returns the output view (sRGB, over black) and its size.- pub fn composite(&mut self, plan: &FramePlan) -> (&wgpu::TextureView, (u32, u32)) {+ pub fn composite(&mut self, plan: &FramePlan) -> (wgpu::TextureView, (u32, u32)) {self.composite_prepared(plan, None)}/// [`composite`](Self::composite) with texel conversions already done by [`prepare`] (the/// result is identical; only the upload work on this thread differs).- pub fn composite_prepared(&mut self, plan: &FramePlan, prep: Option<&PreparedPlan>) -> (&wgpu::TextureView, (u32, u32)) {+ pub fn composite_prepared(&mut self, plan: &FramePlan, prep: Option<&PreparedPlan>) -> (wgpu::TextureView, (u32, u32)) {let owned;let (w, h, layers): (u32, u32, &[PlanLayer]) = match plan {FramePlan::Layers { width, height, layers } => (*width as u32, *height as u32, layers.as_slice()),@@ -469,8 +472,8 @@ impl GpuCompositor {}};let (w, h) = (w.max(1), h.max(1));- Self::target(&self.device, &mut self.accum, w, h, ACCUM_FORMAT, wgpu::TextureUsages::empty());- Self::target(&self.device, &mut self.output, w, h, OUTPUT_FORMAT, wgpu::TextureUsages::COPY_SRC);+ let accum_view = Self::target(&self.device, &mut self.accum, w, h, ACCUM_FORMAT, wgpu::TextureUsages::empty());+ let out_view = Self::target(&self.device, &mut self.output, w, h, OUTPUT_FORMAT, wgpu::TextureUsages::COPY_SRC);let keys: Vec<(usize, u32, u32)> = layers.iter().enumerate()@@ -503,19 +506,17 @@ impl GpuCompositor {});bind_groups.push(bg);}- let accum_view = &self.accum.as_ref().expect("accum").1;- let out_view = &self.output.as_ref().expect("output").1;let final_bg = self.device.create_bind_group(&wgpu::BindGroupDescriptor {label: Some("final"),layout: &self.final_bgl,- entries: &[wgpu::BindGroupEntry { binding: 0, resource: wgpu::BindingResource::TextureView(accum_view) }],+ entries: &[wgpu::BindGroupEntry { binding: 0, resource: wgpu::BindingResource::TextureView(&accum_view) }],});let mut enc = self.device.create_command_encoder(&wgpu::CommandEncoderDescriptor { label: Some("filmcraft-composite") });{let mut pass = enc.begin_render_pass(&wgpu::RenderPassDescriptor {label: Some("layers"),color_attachments: &[Some(wgpu::RenderPassColorAttachment {- view: accum_view,+ view: &accum_view,depth_slice: None,resolve_target: None,ops: wgpu::Operations { load: wgpu::LoadOp::Clear(wgpu::Color::TRANSPARENT), store: wgpu::StoreOp::Store },@@ -535,7 +536,7 @@ impl GpuCompositor {let mut pass = enc.begin_render_pass(&wgpu::RenderPassDescriptor {label: Some("resolve"),color_attachments: &[Some(wgpu::RenderPassColorAttachment {- view: out_view,+ view: &out_view,depth_slice: None,resolve_target: None,ops: wgpu::Operations { load: wgpu::LoadOp::Clear(wgpu::Color::BLACK), store: wgpu::StoreOp::Store },@@ -550,7 +551,7 @@ impl GpuCompositor {pass.draw(0..3, 0..1);}self.queue.submit([enc.finish()]);- (&self.output.as_ref().expect("output").1, (w, h))+ (out_view, (w, h))}/// Read the output back as RGBA8 (tests / screenshots / thumbnails).diff --git a/crates/render/src/lib.rs b/crates/render/src/lib.rsindex cad220a38..f1149b309 100644--- a/crates/render/src/lib.rs+++ b/crates/render/src/lib.rs@@ -7,6 +7,8 @@//!//! The same code renders monitors, thumbnails and exports, and is the oracle for the GPU path.+#![cfg_attr(not(test), deny(clippy::unwrap_used, clippy::expect_used, clippy::panic, clippy::unimplemented, clippy::todo, clippy::unreachable))]+pub mod audio;pub mod audio_fx;pub mod blend;diff --git a/crates/render/src/lumetri_presets.rs b/crates/render/src/lumetri_presets.rsindex aa1e332f1..4cc519844 100644--- a/crates/render/src/lumetri_presets.rs+++ b/crates/render/src/lumetri_presets.rs@@ -28,7 +28,19 @@ pub struct LumetriPreset {impl LumetriPreset {/// A Lumetri Color effect instance configured as the preset.pub fn instance(&self) -> EffectInstance {- let mut e = find_effect("lumetri").expect("lumetri is defined").instance();+ let mut e = match find_effect("lumetri") {+ Some(def) => def.instance(),+ // A bare instance named after the effect; the preset's parameters are added below.+ None => EffectInstance {+ effect: "lumetri".into(),+ enabled: true,+ params: Default::default(),+ masks: Vec::new(),+ post_fader: false,+ essential: false,+ layer: None,+ },+ };for (k, v) in &self.params {if let Some(p) = e.params.get_mut(*k) {p.value = v.clone();diff --git a/crates/render/src/track.rs b/crates/render/src/track.rsindex c73dda8e8..b1e2506e3 100644--- a/crates/render/src/track.rs+++ b/crates/render/src/track.rs@@ -93,7 +93,7 @@ impl Gray {fn pyramid(&self) -> Vec<Gray> {let mut v = vec![self.clone()];while v.len() < LEVELS && v.last().is_some_and(|g| g.w >= 32 && g.h >= 32) {- let n = v.last().map(Gray::down).expect("level");+ let Some(n) = v.last().map(Gray::down) else { break };v.push(n);}vdiff --git a/crates/render/src/vfx/stylize.rs b/crates/render/src/vfx/stylize.rsindex 7e1cb2d1e..712298991 100644--- a/crates/render/src/vfx/stylize.rs+++ b/crates/render/src/vfx/stylize.rs@@ -482,7 +482,9 @@ fn bolt(a: (f32, f32), b: (f32, f32), segs: usize, amp: f32, levels: usize, detanp.push(p);np.push(((p.0 + q.0) / 2.0 - ey / l * o, (p.1 + q.1) / 2.0 + ex / l * o));}- np.push(*pts.last().expect("bolt"));+ if let Some(&last) = pts.last() {+ np.push(last);+ }pts = np;a2 *= 0.5;}