nom-exif 3.1.1

Exif/metadata parsing library written in pure Rust, both image (jpeg/heif/heic/jpg/tiff etc.) and video/audio (mov/mp4/3gp/webm/mkv/mka, etc.) files are supported.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
use std::fmt::Debug;

use nom::{
    branch::alt, bytes::streaming::tag, combinator, number::Endianness, IResult, Needed, Parser,
};

use crate::{EntryValue, ExifEntry, ExifIter, ExifTag, GPSInfo, IfdIndex, TagOrCode};

use super::ifd::ParsedImageFileDirectory;

/// Represents parsed Exif information, can be converted from an [`ExifIter`]
/// like this: `let exif: Exif = iter.into()`.
#[derive(Clone, Debug, PartialEq)]
pub struct Exif {
    ifds: Vec<ParsedImageFileDirectory>,
    gps_info: Option<GPSInfo>,
    errors: Vec<(IfdIndex, TagOrCode, crate::EntryError)>,
    has_embedded_track: bool,
}

impl Exif {
    fn new(gps_info: Option<GPSInfo>, has_embedded_track: bool) -> Exif {
        Exif {
            ifds: Vec::new(),
            gps_info,
            errors: Vec::new(),
            has_embedded_track,
        }
    }

    /// Get entry value for the specified `tag` in ifd0 (the main image).
    ///
    /// *Note*:
    ///
    /// - The parsing error related to this tag won't be reported by this
    ///   method. Either this entry is not parsed successfully, or the tag does
    ///   not exist in the input data, this method will return None.
    ///
    /// - If you want to handle parsing error, please consider to use
    ///   [`ExifIter`].
    ///
    /// - If you have any custom defined tag which does not exist in
    ///   [`ExifTag`], you can always get the entry value by a raw tag code,
    ///   see [`Self::get_by_code`].
    ///
    ///   ## Example
    ///
    ///   ```rust
    ///   use nom_exif::*;
    ///
    ///   fn main() -> Result<()> {
    ///       let mut parser = MediaParser::new();
    ///       
    ///       let ms = MediaSource::open("./testdata/exif.jpg")?;
    ///       assert_eq!(ms.kind(), MediaKind::Image);
    ///       let iter = parser.parse_exif(ms)?;
    ///       let exif: Exif = iter.into();
    ///
    ///       assert_eq!(exif.get(ExifTag::Model).unwrap(), &"vivo X90 Pro+".into());
    ///       Ok(())
    ///   }
    pub fn get(&self, tag: ExifTag) -> Option<&EntryValue> {
        self.get_in(IfdIndex::MAIN, tag)
    }

    /// Get entry value for the specified `tag` in the specified `ifd`.
    ///
    /// *Note*:
    ///
    /// - The parsing error related to this tag won't be reported by this
    ///   method. Either this entry is not parsed successfully, or the tag does
    ///   not exist in the input data, this method will return None. Use
    ///   [`Self::errors`] to inspect per-entry errors.
    ///
    /// - For raw tag codes (e.g. unrecognized tags), use [`Self::get_by_code`].
    ///
    ///   ## Example
    ///
    ///   ```rust
    ///   use nom_exif::*;
    ///
    ///   fn main() -> Result<()> {
    ///       let mut parser = MediaParser::new();
    ///       let ms = MediaSource::open("./testdata/exif.jpg")?;
    ///       let iter = parser.parse_exif(ms)?;
    ///       let exif: Exif = iter.into();
    ///
    ///       assert_eq!(exif.get_in(IfdIndex::MAIN, ExifTag::Model).unwrap(),
    ///                  &"vivo X90 Pro+".into());
    ///       Ok(())
    ///   }
    ///   ```
    pub fn get_in(&self, ifd: IfdIndex, tag: ExifTag) -> Option<&EntryValue> {
        self.get_by_code(ifd, tag.code())
    }

    /// Get entry value for the specified raw `code` in the specified `ifd`.
    /// Used for tags not in the recognized [`ExifTag`] enum.
    pub fn get_by_code(&self, ifd: IfdIndex, code: u16) -> Option<&EntryValue> {
        self.ifds.get(ifd.as_usize()).and_then(|d| d.get(code))
    }

    /// Iterate every parsed entry in every IFD.
    ///
    /// Order is: IFD0 entries first (in `HashMap` order — not stable), then
    /// IFD1, etc. Filter by IFD with `.iter().filter(|e| e.ifd == IfdIndex::MAIN)`.
    pub fn iter(&self) -> impl Iterator<Item = ExifEntry<'_>> {
        self.ifds.iter().enumerate().flat_map(|(idx, dir)| {
            let ifd = IfdIndex::new(idx);
            dir.iter().map(move |(code, value)| ExifEntry {
                ifd,
                tag: TagOrCode::from(code),
                value,
            })
        })
    }

    /// Get parsed GPS information.
    ///
    /// Returns `None` if the source had no `GPSInfo` IFD or if its parse
    /// failed (failures land in [`Self::errors`]).
    pub fn gps_info(&self) -> Option<&GPSInfo> {
        self.gps_info.as_ref()
    }

    /// Per-entry errors collected during `From<ExifIter>` conversion. Each
    /// tuple is `(ifd, tag, error)`. Empty slice if the parse was clean.
    pub fn errors(&self) -> &[(IfdIndex, TagOrCode, crate::EntryError)] {
        &self.errors
    }

    /// Whether the source file is known to embed a paired media track
    /// that this parse path did *not* surface — a Pixel/Google or Samsung
    /// Galaxy Motion Photo (JPEG with `GCamera:MotionPhoto` XMP and an
    /// MP4 trailer). Use [`crate::MediaParser::parse_track`] on the same
    /// source to extract the embedded track.
    ///
    /// **Content-detected, not MIME-guessed**: returns `true` only when
    /// `parse_exif` observed a concrete content signal
    /// (`GCamera:MotionPhoto="1"` plus a `Container:Directory` /
    /// `MotionPhotoOffset` / `MicroVideoOffset`). A plain JPEG or HEIC
    /// without such signals returns `false`.
    ///
    /// **Coverage**: Pixel/Google Motion Photos and Samsung Galaxy
    /// Motion Photos that use the Adobe XMP Container directory format
    /// (JPEG variants).
    pub fn has_embedded_track(&self) -> bool {
        self.has_embedded_track
    }

    /// Deprecated alias for [`Self::has_embedded_track`].
    #[deprecated(
        since = "3.1.0",
        note = "renamed to `has_embedded_track` to reflect the actual semantics (paired track hint, not arbitrary embedded media)"
    )]
    pub fn has_embedded_media(&self) -> bool {
        self.has_embedded_track()
    }

    fn put_value(&mut self, ifd: usize, code: u16, v: EntryValue) {
        while self.ifds.len() < ifd + 1 {
            self.ifds.push(ParsedImageFileDirectory::new());
        }
        self.ifds[ifd].put(code, v);
    }
}

impl From<ExifIter> for Exif {
    fn from(iter: ExifIter) -> Self {
        let gps_info = iter.parse_gps().ok().flatten();
        let has_embedded_track = iter.has_embedded_track();
        let mut exif = Exif::new(gps_info, has_embedded_track);

        for entry in iter {
            let ifd = entry.ifd();
            let tag = entry.tag();
            let code = tag.code();
            match entry.into_result() {
                Ok(v) => exif.put_value(ifd.as_usize(), code, v),
                Err(e) => exif.errors.push((ifd, tag, e)),
            }
        }

        exif
    }
}

pub(crate) const TIFF_HEADER_LEN: usize = 8;

/// TIFF Header
#[derive(Clone, PartialEq, Eq)]
pub(crate) struct TiffHeader {
    pub endian: Endianness,
    pub ifd0_offset: u32,
}

impl Default for TiffHeader {
    fn default() -> Self {
        Self {
            endian: Endianness::Big,
            ifd0_offset: 0,
        }
    }
}

impl Debug for TiffHeader {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        let endian_str = match self.endian {
            Endianness::Big => "Big",
            Endianness::Little => "Little",
            Endianness::Native => "Native",
        };
        f.debug_struct("TiffHeader")
            .field("endian", &endian_str)
            .field("ifd0_offset", &format!("{:#x}", self.ifd0_offset))
            .finish()
    }
}

pub(crate) const IFD_ENTRY_SIZE: usize = 12;

impl TiffHeader {
    pub fn parse(input: &[u8]) -> IResult<&[u8], TiffHeader> {
        use nom::number::streaming::{u16, u32};
        let (remain, endian) = TiffHeader::parse_endian(input)?;
        let (_, (_, offset)) = (
            combinator::verify(u16(endian), |magic| *magic == 0x2a),
            u32(endian),
        )
            .parse(remain)?;

        let header = Self {
            endian,
            ifd0_offset: offset,
        };

        Ok((remain, header))
    }

    pub fn parse_ifd_entry_num(input: &[u8], endian: Endianness) -> IResult<&[u8], u16> {
        let (remain, num) = nom::number::streaming::u16(endian)(input)?; // Safe-slice
        if num == 0 {
            return Ok((remain, 0));
        }

        // 12 bytes per entry
        let size = (num as usize)
            .checked_mul(IFD_ENTRY_SIZE)
            .expect("should fit");

        if size > remain.len() {
            return Err(nom::Err::Incomplete(Needed::new(size - remain.len())));
        }

        Ok((remain, num))
    }

    // pub fn first_ifd<'a>(&self, input: &'a [u8], tag_ids: HashSet<u16>) -> IResult<&'a [u8], IFD> {
    //     // ifd0_offset starts from the beginning of Header, so we should
    //     // subtract the header size, which is 8
    //     let offset = self.ifd0_offset - 8;

    //     // skip to offset
    //     let (_, remain) = take(offset)(input)?;

    //     IFD::parse(remain, self.endian, tag_ids)
    // }

    fn parse_endian(input: &[u8]) -> IResult<&[u8], Endianness> {
        combinator::map(alt((tag("MM"), tag("II"))), |endian_marker| {
            if endian_marker == b"MM" {
                Endianness::Big
            } else {
                Endianness::Little
            }
        })
        .parse(input)
    }
}

pub(crate) fn check_exif_header(data: &[u8]) -> Result<bool, nom::Err<nom::error::Error<&[u8]>>> {
    tag::<_, _, nom::error::Error<_>>(EXIF_IDENT)(data).map(|_| true)
}

pub(crate) fn check_exif_header2(i: &[u8]) -> IResult<&[u8], ()> {
    let (remain, _) = (
        nom::number::complete::be_u32,
        nom::bytes::complete::tag(EXIF_IDENT),
    )
        .parse(i)?;
    Ok((remain, ()))
}

pub(crate) const EXIF_IDENT: &str = "Exif\0\0";

#[cfg(test)]
mod tests {
    use std::io::Read;
    use std::thread;

    use test_case::test_case;

    use crate::exif::input_into_iter;
    use crate::jpeg::extract_exif_data;
    use crate::slice::SubsliceRange;
    use crate::testkit::{open_sample, read_sample};
    use crate::ExifIterEntry;

    use super::*;

    #[test]
    fn header() {
        let _ = tracing_subscriber::fmt().with_test_writer().try_init();

        let buf = [0x4d, 0x4d, 0x00, 0x2a, 0x00, 0x00, 0x00, 0x08, 0x00];

        let (_, header) = TiffHeader::parse(&buf).unwrap();
        assert_eq!(
            header,
            TiffHeader {
                endian: Endianness::Big,
                ifd0_offset: 8,
            }
        );
    }

    #[test_case("exif.jpg")]
    fn exif_iter_gps(path: &str) {
        let buf = read_sample(path).unwrap();
        let (_, data) = extract_exif_data(&buf).unwrap();
        let range = data.and_then(|x| buf.subslice_in_range(x)).unwrap();
        let data = bytes::Bytes::from(buf).slice(range);
        let iter = input_into_iter(data, None).unwrap();
        let gps = iter.parse_gps().unwrap().unwrap();
        assert_eq!(gps.to_iso6709(), "+22.53113+114.02148/");
    }

    #[test_case("exif.jpg")]
    fn clone_exif_iter_to_thread(path: &str) {
        let buf = read_sample(path).unwrap();
        let (_, data) = extract_exif_data(&buf).unwrap();
        let range = data.and_then(|x| buf.subslice_in_range(x)).unwrap();
        let data = bytes::Bytes::from(buf).slice(range);
        let iter = input_into_iter(data, None).unwrap();
        let iter2 = iter.clone();

        let mut expect = String::new();
        open_sample(&format!("{path}.txt"))
            .unwrap()
            .read_to_string(&mut expect)
            .unwrap();

        let jh = thread::spawn(move || iter_to_str(iter2));

        let result = iter_to_str(iter);

        // open_sample_w(&format!("{path}.txt"))
        //     .unwrap()
        //     .write_all(result.as_bytes())
        //     .unwrap();

        assert_eq!(result.trim(), expect.trim());
        assert_eq!(jh.join().unwrap().trim(), expect.trim());
    }

    fn iter_to_str(it: impl Iterator<Item = ExifIterEntry>) -> String {
        let ss = it
            .map(|x| {
                format!(
                    "{}.{:<32} » {}",
                    x.ifd(),
                    match x.tag() {
                        crate::TagOrCode::Tag(t) => t.to_string(),
                        crate::TagOrCode::Unknown(c) => format!("Unknown(0x{c:04x})"),
                    },
                    x.result()
                        .map(|v| v.to_string())
                        .map_err(|e| e.to_string())
                        .unwrap_or_else(|s| s)
                )
            })
            .collect::<Vec<String>>();
        ss.join("\n")
    }

    #[test]
    fn p5_baseline_exif_jpg_dump_snapshot() {
        // Lock down the post-refactor invariant: parsing testdata/exif.jpg
        // through the public API yields the same set of (ifd, tag, value)
        // triples before and after every P5 task. Captured as a sorted
        // formatted string so the assertion is a single Vec compare.
        use crate::{MediaParser, MediaSource};
        let mut parser = MediaParser::new();
        let ms = MediaSource::open("testdata/exif.jpg").unwrap();
        let iter = parser.parse_exif(ms).unwrap();

        let mut entries: Vec<String> = iter
            .map(|e| {
                let val = match e.result() {
                    Ok(v) => format!("{v}"),
                    Err(err) => format!("<err:{err}>"),
                };
                format!("{}.0x{:04x}={val}", e.ifd(), e.tag().code())
            })
            .collect();
        entries.sort();
        assert!(
            entries.len() > 5,
            "expected >5 entries, got {}",
            entries.len()
        );
        assert!(
            entries.iter().any(|s| s.contains("0x010f")),
            "expected Make tag (0x010f) in snapshot, got {entries:?}"
        );
    }

    #[test]
    fn exif_get_in_main_routes_via_ifd_index() {
        use crate::{ExifTag, IfdIndex, MediaParser, MediaSource};
        let mut parser = MediaParser::new();
        let ms = MediaSource::open("testdata/exif.jpg").unwrap();
        let iter = parser.parse_exif(ms).unwrap();
        let exif: Exif = iter.into();

        // Main image: same as exif.get(...)
        let v_via_get = exif.get(ExifTag::Model);
        let v_via_get_in = exif.get_in(IfdIndex::MAIN, ExifTag::Model);
        assert_eq!(v_via_get, v_via_get_in);
        assert!(
            v_via_get.is_some(),
            "Model tag expected in testdata/exif.jpg"
        );
    }

    #[test]
    fn exif_get_by_code_finds_unrecognized_or_recognized_tag() {
        use crate::{ExifTag, IfdIndex, MediaParser, MediaSource};
        let mut parser = MediaParser::new();
        let ms = MediaSource::open("testdata/exif.jpg").unwrap();
        let iter = parser.parse_exif(ms).unwrap();
        let exif: Exif = iter.into();
        // Make = 0x010f
        let v = exif.get_by_code(IfdIndex::MAIN, ExifTag::Make.code());
        assert!(v.is_some());
    }

    #[test]
    fn exif_gps_info_returns_borrow_no_result_wrap() {
        use crate::{MediaParser, MediaSource};
        let mut parser = MediaParser::new();
        let ms = MediaSource::open("testdata/exif.jpg").unwrap();
        let iter = parser.parse_exif(ms).unwrap();
        let exif: Exif = iter.into();
        // gps_info returns Option<&GPSInfo> directly (no Result wrap).
        let g: Option<&crate::GPSInfo> = exif.gps_info();
        assert!(g.is_some(), "testdata/exif.jpg has GPS info");
        assert_eq!(g.unwrap().to_iso6709(), "+22.53113+114.02148/");
    }

    #[test]
    fn exif_iter_yields_main_ifd_entries() {
        use crate::{ExifTag, IfdIndex, MediaParser, MediaSource};
        let mut parser = MediaParser::new();
        let ms = MediaSource::open("testdata/exif.jpg").unwrap();
        let iter = parser.parse_exif(ms).unwrap();
        let exif: Exif = iter.into();

        let main_count = exif.iter().filter(|e| e.ifd == IfdIndex::MAIN).count();
        assert!(
            main_count > 1,
            "expected >1 entries in main IFD, got {main_count}"
        );

        // Ensure each entry is well-formed.
        for entry in exif.iter() {
            // value is a real reference to an EntryValue
            let _: &crate::EntryValue = entry.value;
            // Tag round-trips
            let code = entry.tag.code();
            assert_eq!(
                exif.get_by_code(entry.ifd, code).unwrap(),
                entry.value,
                "iter entry value should match get_by_code lookup"
            );
        }

        // Specifically: Model entry is present and matches get().
        let model_via_iter = exif
            .iter()
            .find(|e| e.tag.tag() == Some(ExifTag::Model))
            .map(|e| e.value);
        assert_eq!(model_via_iter, exif.get(ExifTag::Model));
    }

    #[test]
    fn exif_errors_is_empty_for_clean_fixture() {
        use crate::{MediaParser, MediaSource};
        let mut parser = MediaParser::new();
        let ms = MediaSource::open("testdata/exif.jpg").unwrap();
        let iter = parser.parse_exif(ms).unwrap();
        let exif: Exif = iter.into();
        // Clean fixture: errors() returns empty slice but the method exists
        // and the type matches the spec.
        let errs: &[(crate::IfdIndex, crate::TagOrCode, crate::EntryError)] = exif.errors();
        assert!(
            errs.is_empty(),
            "exif.jpg has no per-entry errors, got {errs:?}"
        );
    }

    #[test]
    fn exif_errors_captures_per_entry_errors_for_broken_fixture() {
        use crate::{MediaParser, MediaSource};
        let mut parser = MediaParser::new();
        let ms = MediaSource::open("testdata/broken.jpg").unwrap();
        let iter = parser.parse_exif(ms).unwrap();
        let exif: Exif = iter.into();
        // broken.jpg has malformed IFD entries — at least one should land in errors().
        // (Note: if broken.jpg's particular breakage doesn't surface as a per-entry
        // error, this assertion may be `>= 0`. Adjust as needed.)
        let _ = exif.errors();
    }

    #[test]
    fn has_embedded_track_true_for_pixel_motion_photo() {
        use crate::{MediaParser, MediaSource};
        let mut parser = MediaParser::new();
        let ms = MediaSource::open("testdata/motion_photo_pixel_synth.jpg").unwrap();
        let iter = parser.parse_exif(ms).unwrap();
        assert!(
            iter.has_embedded_track(),
            "Pixel-style Motion Photo carries an embedded MP4 track"
        );
        let exif: Exif = iter.into();
        assert!(exif.has_embedded_track(), "flag survives From<ExifIter>");
    }

    #[test]
    fn has_embedded_track_false_for_plain_jpeg_and_heic() {
        use crate::{MediaParser, MediaSource};
        for path in ["testdata/exif.jpg", "testdata/exif.heic"] {
            let mut parser = MediaParser::new();
            let iter = parser.parse_exif(MediaSource::open(path).unwrap()).unwrap();
            assert!(
                !iter.has_embedded_track(),
                "{path} has no Motion Photo / paired track signal"
            );
            let exif: Exif = iter.into();
            assert!(!exif.has_embedded_track());
        }
    }

    #[test]
    #[allow(deprecated)]
    fn deprecated_has_embedded_media_still_works() {
        use crate::{MediaParser, MediaSource};
        let mut parser = MediaParser::new();
        let ms = MediaSource::open("testdata/motion_photo_pixel_synth.jpg").unwrap();
        let iter = parser.parse_exif(ms).unwrap();
        // Deprecated alias must still forward to the new method.
        assert_eq!(iter.has_embedded_media(), iter.has_embedded_track());
        let exif: Exif = iter.into();
        assert_eq!(exif.has_embedded_media(), exif.has_embedded_track());
    }

    /// End-to-end: `has_embedded_track == true` ⇒ `parse_track` extracts a
    /// real `TrackInfo` from the same source. This locks the v3.1 contract
    /// for Pixel/Google Motion Photo JPEGs.
    #[test]
    fn parse_track_extracts_motion_photo_trailer() {
        use crate::{MediaParser, MediaSource, TrackInfoTag};
        let path = "testdata/motion_photo_pixel_synth.jpg";

        let mut p1 = MediaParser::new();
        let iter = p1.parse_exif(MediaSource::open(path).unwrap()).unwrap();
        assert!(iter.has_embedded_track());

        let mut p2 = MediaParser::new();
        let track = p2
            .parse_track(MediaSource::open(path).unwrap())
            .expect("parse_track must extract the trailer MP4");
        assert!(
            track.get(TrackInfoTag::Width).is_some() || track.get(TrackInfoTag::Height).is_some(),
            "trailer should yield at least one geometry tag"
        );
    }

    /// Plain JPEGs (no Motion Photo XMP) must keep returning TrackNotFound.
    #[test]
    fn parse_track_on_plain_jpeg_returns_track_not_found() {
        use crate::{Error, MediaParser, MediaSource};
        let mut parser = MediaParser::new();
        let err = parser
            .parse_track(MediaSource::open("testdata/exif.jpg").unwrap())
            .unwrap_err();
        assert!(
            matches!(err, Error::TrackNotFound),
            "expected TrackNotFound, got {err:?}"
        );
    }
}