Skip to content

Commit e7a9ae2

Browse files
committed
error: Move ErrorKind::BadAtom to aud_io
1 parent d272232 commit e7a9ae2

File tree

5 files changed

+20
-23
lines changed

5 files changed

+20
-23
lines changed

lofty/src/error.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,7 @@ pub enum ErrorKind {
5050
BadTimestamp(&'static str),
5151
/// Errors that arise while reading/writing ID3v2 tags
5252
Id3v2(Id3v2Error),
53-
54-
/// Arises when an atom contains invalid data
55-
BadAtom(&'static str),
53+
5654
/// Arises when attempting to use [`Atom::merge`](crate::mp4::Atom::merge) with mismatching identifiers
5755
AtomMismatch,
5856

@@ -521,7 +519,6 @@ impl Display for LoftyError {
521519
write!(f, "Encountered an invalid timestamp: {message}")
522520
},
523521
ErrorKind::Id3v2(ref id3v2_err) => write!(f, "{id3v2_err}"),
524-
ErrorKind::BadAtom(message) => write!(f, "MP4 Atom: {message}"),
525522
ErrorKind::AtomMismatch => write!(
526523
f,
527524
"MP4 Atom: Attempted to use `Atom::merge()` with mismatching identifiers"

lofty/src/mp4/ilst/read.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use super::{Atom, AtomData, AtomIdent, Ilst};
44
use crate::config::{ParseOptions, ParsingMode};
55
use crate::error::{LoftyError, Result};
66
use crate::id3::v1::constants::GENRES;
7-
use crate::macros::{err, try_vec};
7+
use crate::macros::try_vec;
88
use crate::mp4::ilst::atom::AtomDataStorage;
99
use crate::mp4::read::skip_atom;
1010
use crate::picture::{MimeType, Picture, PictureType};
@@ -13,6 +13,7 @@ use crate::tag::TagExt;
1313
use std::borrow::Cow;
1414
use std::io::{Cursor, Read, Seek, SeekFrom};
1515

16+
use aud_io::err as io_err;
1617
use aud_io::text::{utf8_decode, utf16_decode_bytes};
1718
use aud_io::mp4::{ATOM_HEADER_LEN, AtomInfo, AtomReader};
1819

@@ -259,15 +260,15 @@ where
259260
next_atom.len
260261
);
261262
if parsing_mode == ParsingMode::Strict {
262-
err!(BadAtom("Data atom is too small"))
263+
io_err!(BadAtom("Data atom is too small"))
263264
}
264265

265266
break;
266267
}
267268

268269
if next_atom.ident != DATA_ATOM_IDENT {
269270
if parsing_mode == ParsingMode::Strict {
270-
err!(BadAtom("Expected atom \"data\" to follow name"))
271+
io_err!(BadAtom("Expected atom \"data\" to follow name"))
271272
}
272273

273274
log::warn!(
@@ -323,7 +324,7 @@ where
323324
let type_set = reader.read_u8()?;
324325
if type_set != WELL_KNOWN_TYPE_SET {
325326
if parsing_mode == ParsingMode::Strict {
326-
err!(BadAtom("Unknown type set in data atom"))
327+
io_err!(BadAtom("Unknown type set in data atom"))
327328
}
328329

329330
return Ok(None);
@@ -338,7 +339,7 @@ fn parse_uint(bytes: &[u8]) -> Result<u32> {
338339
2 => u32::from(u16::from_be_bytes([bytes[0], bytes[1]])),
339340
3 => u32::from_be_bytes([0, bytes[0], bytes[1], bytes[2]]),
340341
4 => u32::from_be_bytes([bytes[0], bytes[1], bytes[2], bytes[3]]),
341-
_ => err!(BadAtom(
342+
_ => io_err!(BadAtom(
342343
"Unexpected atom size for type \"BE unsigned integer\""
343344
)),
344345
})
@@ -350,7 +351,7 @@ fn parse_int(bytes: &[u8]) -> Result<i32> {
350351
2 => i32::from(i16::from_be_bytes([bytes[0], bytes[1]])),
351352
3 => i32::from_be_bytes([0, bytes[0], bytes[1], bytes[2]]),
352353
4 => i32::from_be_bytes([bytes[0], bytes[1], bytes[2], bytes[3]]),
353-
_ => err!(BadAtom(
354+
_ => io_err!(BadAtom(
354355
"Unexpected atom size for type \"BE signed integer\""
355356
)),
356357
})
@@ -380,7 +381,7 @@ where
380381
DataType::Bmp => Some(MimeType::Bmp),
381382
_ => {
382383
if parsing_mode == ParsingMode::Strict {
383-
err!(BadAtom("\"covr\" atom has an unknown type"))
384+
io_err!(BadAtom("\"covr\" atom has an unknown type"))
384385
}
385386

386387
log::warn!(

lofty/src/mp4/properties.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
use super::read::{find_child_atom, skip_atom};
22
use crate::config::ParsingMode;
33
use crate::error::{LoftyError, Result};
4-
use crate::macros::{decode_err, err, try_vec};
4+
use crate::macros::{decode_err, try_vec};
55
use crate::properties::FileProperties;
66

77
use std::io::{Cursor, Read, Seek, SeekFrom};
88
use std::time::Duration;
99

10+
use aud_io::err as io_err;
1011
use aud_io::mp4::{AtomReader, AtomIdent, AtomInfo};
1112
use aud_io::alloc::VecFallibleCapacity;
1213
use aud_io::math::RoundedDivision;
@@ -285,7 +286,7 @@ where
285286
}
286287

287288
let Some(mdhd) = mdhd else {
288-
err!(BadAtom("Expected atom \"trak.mdia.mdhd\""));
289+
io_err!(BadAtom("Expected atom \"trak.mdia.mdhd\""));
289290
};
290291

291292
Ok(AudioTrak { mdhd, minf })
@@ -433,11 +434,11 @@ where
433434

434435
for _ in 0..num_sample_entries {
435436
let Some(atom) = reader.next()? else {
436-
err!(BadAtom("Expected sample entry atom in `stsd` atom"))
437+
io_err!(BadAtom("Expected sample entry atom in `stsd` atom"))
437438
};
438439

439440
let AtomIdent::Fourcc(ref fourcc) = atom.ident else {
440-
err!(BadAtom("Expected fourcc atom in `stsd` atom"))
441+
io_err!(BadAtom("Expected fourcc atom in `stsd` atom"))
441442
};
442443

443444
match fourcc {

lofty/src/mp4/read.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use super::Mp4File;
22
use super::moov::Moov;
33
use super::properties::Mp4Properties;
44
use crate::config::{ParseOptions, ParsingMode};
5-
use crate::error::{ErrorKind, LoftyError, Result};
5+
use crate::error::Result;
66
use crate::macros::{decode_err, err};
77

88
use std::io::{Read, Seek, SeekFrom};
@@ -36,11 +36,9 @@ where
3636

3737
reader.seek(SeekFrom::Current((atom.len - 12) as i64))?;
3838

39-
let major_brand = utf8_decode_str(&major_brand)
40-
.map(ToOwned::to_owned)
41-
.map_err(|_| {
42-
LoftyError::new(ErrorKind::BadAtom("Unable to parse \"ftyp\"'s major brand"))
43-
})?;
39+
let Ok(major_brand) = utf8_decode_str(&major_brand).map(ToOwned::to_owned) else {
40+
io_err!(BadAtom("Unable to parse \"ftyp\"'s major brand"));
41+
};
4442

4543
log::debug!("Verified to be an MP4 file. Major brand: {}", major_brand);
4644
Ok(major_brand)

lofty/src/mp4/write.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
use crate::config::ParsingMode;
22
use crate::error::{LoftyError, Result};
33
use crate::io::{FileLike, Length, Truncate};
4-
use crate::macros::err;
54
use crate::mp4::read::{meta_is_full, skip_atom};
65

76
use std::cell::{RefCell, RefMut};
87
use std::io::{Cursor, Read, Seek, SeekFrom, Write};
98
use std::ops::RangeBounds;
109

10+
use aud_io::err as io_err;
1111
use aud_io::mp4::{AtomIdent, AtomInfo, IDENTIFIER_LEN};
1212
use byteorder::{BigEndian, WriteBytesExt};
1313

@@ -75,7 +75,7 @@ impl ContextualAtom {
7575

7676
if len != 0 {
7777
// TODO: Print the container ident
78-
err!(BadAtom("Unable to read entire container"));
78+
io_err!(BadAtom("Unable to read entire container"));
7979
}
8080

8181
*reader_len = reader_len.saturating_sub(info.len);

0 commit comments

Comments
 (0)