Skip to content

Commit

Permalink
Add check for config.fail_on_decode_error
Browse files Browse the repository at this point in the history
  • Loading branch information
benfmiller committed Sep 22, 2024
1 parent 4da464c commit e5e30b2
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 7 deletions.
4 changes: 3 additions & 1 deletion audalign/recognizers/correcognize/correcognize.py
Original file line number Diff line number Diff line change
Expand Up @@ -336,8 +336,10 @@ def _correcognize_dir(
**kwargs,
)

except CouldntDecodeError:
except CouldntDecodeError as e:
print(f'File "{against_file_path}" could not be decoded')
if config.fail_on_decode_error:
raise e
return {}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -336,8 +336,10 @@ def _correcognize_dir(
**kwargs,
)

except CouldntDecodeError:
except CouldntDecodeError as e:
print(f'File "{against_file_path}" could not be decoded')
if config.fail_on_decode_error:
raise e
return {}


Expand Down
3 changes: 3 additions & 0 deletions audalign/recognizers/fingerprint/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import pickle
import json
import typing
from pydub.exceptions import CouldntDecodeError


class FingerprintRecognizer(BaseRecognizer):
Expand Down Expand Up @@ -266,6 +267,8 @@ def _fingerprint_directory(
print("All files in directory already fingerprinted")
else:
print("Directory contains 0 files or could not be found")
if self.config.fail_on_decode_error:
raise CouldntDecodeError("Directory contains 0 files or could not be found")
return

if _file_audsegs is not None:
Expand Down
10 changes: 6 additions & 4 deletions audalign/recognizers/fingerprint/fingerprinter.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,12 @@ def _fingerprint_worker(
except FileNotFoundError:
print(f'"{file_path}" not found')
return None, None
except (
CouldntDecodeError,
IndexError,
): # Pydub throws IndexErrors for some files on Ubuntu (json, txt, others?)
except CouldntDecodeError as e:
print(f'File "{file_name}" could not be decoded')
if config.fail_on_decode_error:
raise e
return None, None
except IndexError: # Pydub throws IndexErrors for some files on Ubuntu (json, txt, others?)
print(f'File "{file_name}" could not be decoded')
return None, None
elif type(file_path) == tuple:
Expand Down
4 changes: 3 additions & 1 deletion audalign/recognizers/visrecognize/visrecognize.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,10 @@ def _visrecognize_directory(
imgB_title=os.path.basename(file_path),
)
return single_file_match
except CouldntDecodeError:
except CouldntDecodeError as e:
print(f'File "{file_path}" could not be decoded')
if config.fail_on_decode_error:
raise e
return {}


Expand Down

0 comments on commit e5e30b2

Please sign in to comment.