Skip to content

FilmCraft: An open-source, nonlinear video editor written by scratch in pure Rust

captions: captions.list with a track that names no caption track is an error

lloyd8175b16a4752
diff --git a/crates/engine/src/captions.rs b/crates/engine/src/captions.rs
index 644282761..1566a596d 100644
--- a/crates/engine/src/captions.rs
+++ b/crates/engine/src/captions.rs
@@ -513,7 +513,11 @@ pub fn commands() -> Vec<CommandSpec> {
enabled: always,
run: |s, p| {
let Some(seq) = s.active_sequence() else { return Ok(json!({"tracks": []})) };
- let only = p.get("track").and_then(|_| track_param(s, p));
+ // a `track` that names no caption track is an error, never every track
+ let only = match p.get("track") {
+ Some(_) => Some(track_param(s, p).ok_or_else(|| bad("captions.list", "no such caption track"))?),
+ None => None,
+ };
let tracks: Vec<Value> =
seq.caption_tracks.iter().enumerate().filter(|(_, t)| only.is_none_or(|o| o == t.id)).map(|(i, t)| track_json(s, t, i)).collect();
Ok(json!({"tracks": tracks, "selection": s.state.caption_selection.iter().map(|c| c.0).collect::<Vec<_>>()}))
diff --git a/crates/engine/src/captions_tests.rs b/crates/engine/src/captions_tests.rs
index 2167d4b77..feb65c175 100644
--- a/crates/engine/src/captions_tests.rs
+++ b/crates/engine/src/captions_tests.rs
@@ -137,3 +137,24 @@ fn caption_commands_need_tracks_and_navigate() {
s.execute("captions.deleteTrack", json!({"track": "C1"})).unwrap();
assert!(s.active_sequence().unwrap().caption_tracks.is_empty());
}
+
+#[test]
+fn caption_list_track_filter_never_falls_back_to_every_track() {
+ let mut s = demo();
+ s.execute("captions.newTrack", json!({})).unwrap();
+ s.execute("captions.newTrack", json!({})).unwrap();
+ let all = s.execute("captions.list", json!({})).unwrap();
+ let ids: Vec<u64> = all["tracks"].as_array().unwrap().iter().map(|t| t["id"].as_u64().unwrap()).collect();
+ assert_eq!(ids.len(), 2, "{all}");
+ for (i, id) in ids.iter().enumerate() {
+ for sel in [json!(id), json!(format!("C{}", i + 1))] {
+ let r = s.execute("captions.list", json!({"track": sel})).unwrap();
+ let got: Vec<u64> = r["tracks"].as_array().unwrap().iter().map(|t| t["id"].as_u64().unwrap()).collect();
+ assert_eq!(got, vec![*id], "{sel}");
+ }
+ }
+ let missing = ids.iter().max().unwrap() + 999;
+ for sel in [json!(missing), json!("C3"), json!("C0"), json!("nope")] {
+ assert!(s.execute("captions.list", json!({"track": sel})).is_err(), "{sel} names no caption track");
+ }
+}
diff --git a/docs/captions.md b/docs/captions.md
index 12564ddd8..fd76483e2 100644
--- a/docs/captions.md
+++ b/docs/captions.md
@@ -52,7 +52,7 @@ Details of each format and the SCC encoder are in [`crates/captions/README.md`](
| `captions.setStyle` | Text panel style strip | `track`, `size`, `color`, `background`, `backgroundColor`, `outline`, `outlineColor`, `align`, `anchor`, `margin`, `lineSpacing`, `reset` |
| `captions.deleteTrack` | | `track` |
| `captions.import` / `captions.export` | File ▸ Export ▸ Captions… | `path`, `format`, `track`, `dropFrame` |
-| `captions.list` | (query) | `track` — tracks, styles and captions with timecodes |
+| `captions.list` | (query) | `track` — tracks, styles and captions with timecodes (a `track` that names no caption track is an error) |
Tracks are addressed by id or `"C1"`, `"C2"`… (top first). Edits are limited by neighbouring
captions and a one-frame minimum. Sync-locked caption tracks follow insert and extract edits on