Skip to content

Commit

Permalink
Raise FormatError in model, TagError in tag
Browse files Browse the repository at this point in the history
  • Loading branch information
thebigmunch committed Apr 20, 2020
1 parent 189cd6e commit df2999f
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions src/audio_metadata/formats/id3v2frames.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,16 +264,16 @@ def parse(cls, data, *, id3v22=False):
try:
description, image_data = split_encoded(data[mime_end + 2:], encoding, 1)
except ValueError:
raise TagError("Missing data in picture frame.") from None
raise FormatError("Missing data in ID3v2 picture.") from None
else:
if not image_data.strip(b'\x00'):
raise TagError("No image data in picture frame.")
raise FormatError("No image data in picture frame.")

description = decode_bytestring(description, encoding)
try:
width, height = get_image_size(image_data)
except ValueError as exc:
raise TagError(str(exc)) from None
except ValueError:
raise FormatError("Missing width/height in ID3v2 picture.") from None

return cls(
type=type_,
Expand Down Expand Up @@ -1342,8 +1342,13 @@ class ID3v2APICFrame(ID3v2Frame):
def _parse_frame_data(data):
frame_data = data.read()

try:
picture = ID3v2Picture.parse(frame_data)
except FormatError as exc:
raise TagError(str(exc)) from None

return (
ID3v2Picture.parse(frame_data),
picture,
None,
)

Expand All @@ -1358,8 +1363,13 @@ class ID3v2PICFrame(ID3v2Frame):
def _parse_frame_data(data):
frame_data = data.read()

try:
picture = ID3v2Picture.parse(frame_data, id3v22=True)
except FormatError as exc:
raise TagError(str(exc)) from None

return (
ID3v2Picture.parse(frame_data, id3v22=True),
picture,
None,
)

Expand Down

0 comments on commit df2999f

Please sign in to comment.