From a864f0c27eba27cb5069d78e2b4f676b81fb23e0 Mon Sep 17 00:00:00 2001 From: "Dylan M. Taylor" Date: Sun, 15 Nov 2026 17:41:29 +0000 Subject: [PATCH] timeline: offer bounded FCPXML diagnostics --- crates/timeline/src/fcpxml.rs | 100 ++++++++++++++++++++--------- crates/timeline/src/report.rs | 11 ++++ crates/timeline/tests/it/fcpxml.rs | 16 +++++ 3 files changed, 96 insertions(+), 31 deletions(-) diff --git a/crates/timeline/src/fcpxml.rs b/crates/timeline/src/fcpxml.rs index 4a255ba43..88cbce1cf 100644 --- a/crates/timeline/src/fcpxml.rs +++ b/crates/timeline/src/fcpxml.rs @@ -139,6 +139,7 @@ struct Imp<'a, 'c, 'r> { b: Builder<'c>, opts: &'a ImportOptions<'a>, report: &'r mut Report, + report_limit: Option, formats: HashMap, asset_nodes: HashMap>, assets: HashMap, @@ -181,6 +182,10 @@ struct Ctx { /// Read an FCPXML document. Media paths are resolved against `opts.base_dir`; filters are looked /// up in `opts.catalog` by name. What cannot be represented is in `report`. pub fn import(text: &str, opts: &ImportOptions, report: &mut Report) -> Result { + import_with_report_limit(text, opts, report, None) +} +/// Read FCPXML with an optional distinct-diagnostic limit. +pub fn import_with_report_limit(text: &str, opts: &ImportOptions, report: &mut Report, report_limit: Option) -> Result { let doc = crate::xml::parse(text).map_err(|e| Error::parse(Format::Fcpxml, e))?; let root = Node(&doc); if root.name() != "fcpxml" { @@ -189,7 +194,7 @@ pub fn import(text: &str, opts: &ImportOptions, report: &mut Report) -> Result().ok()).unwrap_or(0); if !v.starts_with("1.") || minor > 11 { - report.info(format!("FCPXML version {v} is newer than 1.11; unknown elements were ignored")); + report.info_limited(report_limit, format!("FCPXML version {v} is newer than 1.11; unknown elements were ignored")); } } let lib_name = child(root, "library").and_then(|l| child(l, "event")).and_then(|e| e.attribute("name")).unwrap_or("Imported FCPXML"); @@ -197,6 +202,7 @@ pub fn import(text: &str, opts: &ImportOptions, report: &mut Report) -> Result Result { let rate = match r.attribute("frameDuration") { Some(fd) => rate_from_frame_duration(fd).unwrap_or_else(|| { - imp.report.warn(format!("format \"{id}\" has an invalid frameDuration \"{fd}\"; the default frame rate was used")); + imp.report.warn_limited( + imp.report_limit, + format!("format \"{id}\" has an invalid frameDuration \"{fd}\"; the default frame rate was used"), + ); FrameRate::default() }), None => FrameRate::default(), @@ -274,7 +283,7 @@ pub fn import(text: &str, opts: &ImportOptions, report: &mut Report) -> Result Imp<'a, '_, '_> { self.b.file_media(&format!("file:{p}"), &name, &p, &spec, bin) } None => { - self.report.warn(format!("asset \"{name}\" has no media; imported offline")); + self.report.warn_limited(self.report_limit, format!("asset \"{name}\" has no media; imported offline")); let p = resolve_path(&name, self.opts.base_dir); let it = self.b.file_media(&format!("asset:{id}"), &name, &p, &spec, bin); if let Some(m) = self.b.p.item_mut(it).and_then(|i| i.as_media_mut()) { @@ -365,7 +374,7 @@ impl<'a> Imp<'a, '_, '_> { // Check before the cache: a truncated resource may already have an item while it // is being rebuilt, but a back-edge must never turn that item into a self-cycle. if self.media_active.contains(id) { - self.report.warn(format!("recursive FCPXML media resource {id:?} ignored")); + self.report.warn_limited(self.report_limit, format!("recursive FCPXML media resource {id:?} ignored")); return None; } let depth = self.media_active.len(); @@ -381,9 +390,10 @@ impl<'a> Imp<'a, '_, '_> { if !shallower || self.reimports_left == 0 { if self.cache_reaches_active(i) { self.depth_hits += 1; - self.report.warn(format!( - "FCPXML cached media {id:?} could form a recursive graph or exceeds the cache traversal budget; imported as a gap" - )); + self.report.warn_limited( + self.report_limit, + format!("FCPXML cached media {id:?} could form a recursive graph or exceeds the cache traversal budget; imported as a gap"), + ); return None; } return Some(i); @@ -397,7 +407,7 @@ impl<'a> Imp<'a, '_, '_> { // would otherwise recurse once per resource. if depth >= MAX_MEDIA_DEPTH { self.depth_hits += 1; - self.report.warn(format!("FCPXML media resource {id:?} is nested too deeply; imported as a gap")); + self.report.warn_limited(self.report_limit, format!("FCPXML media resource {id:?} is nested too deeply; imported as a gap")); return None; } self.media_active.insert(id.into()); @@ -445,7 +455,10 @@ impl<'a> Imp<'a, '_, '_> { fn storyline(&mut self, seq: &mut Sequence, ctx: &Ctx, spine: Node<'a>, origin: Tick, lane: i32, primary: bool) { if self.depth >= MAX_XML_DEPTH { self.depth_hits += 1; - self.report.warn(format!("XML storylines are nested too deeply (more than {MAX_XML_DEPTH}); deeper clips were skipped")); + self.report.warn_limited( + self.report_limit, + format!("XML storylines are nested too deeply (more than {MAX_XML_DEPTH}); deeper clips were skipped"), + ); return; } self.depth += 1; @@ -471,7 +484,7 @@ impl<'a> Imp<'a, '_, '_> { let vidx = if lane >= 0 { lane as usize } else { usize::MAX }; for (pos, el) in transitions { if vidx == usize::MAX { - self.report.warn("transitions on audio storylines are not supported"); + self.report.warn_limited(self.report_limit, "transitions on audio storylines are not supported"); continue; } let start = origin + attr_time(el, "offset").unwrap_or(Tick::ZERO); @@ -499,7 +512,13 @@ impl<'a> Imp<'a, '_, '_> { } else { TransitionAlign::CenterAtCut }; - let effect = transition_effect(self.b.catalog, &name, false, self.report); + let mut temporary = Report::default(); + let effect = transition_effect(self.b.catalog, &name, false, &mut temporary); + for e in temporary.entries { + for _ in 0..e.count { + self.report.warn_limited(self.report_limit, &e.message); + } + } let id = TransitionId(self.b.alloc()); // The clips may have been moved to another track by placement; find the track holding them. let clip = from.or(to).map(|c| c.0); @@ -525,7 +544,10 @@ impl<'a> Imp<'a, '_, '_> { fn element(&mut self, seq: &mut Sequence, ctx: &Ctx, el: Node<'a>, t0: Tick, lane: i32, primary: bool) -> (Tick, Option) { if self.depth >= MAX_XML_DEPTH { self.depth_hits += 1; - self.report.warn(format!("XML elements are nested too deeply (more than {MAX_XML_DEPTH}); deeper clips were skipped")); + self.report.warn_limited( + self.report_limit, + format!("XML elements are nested too deeply (more than {MAX_XML_DEPTH}); deeper clips were skipped"), + ); return (t0, None); } self.depth += 1; @@ -554,7 +576,8 @@ impl<'a> Imp<'a, '_, '_> { .flatten() .filter(|a| a.has_video); if asset.is_none() { - self.report.warn(format!("FCPXML