From 803553fd68b0b23aa31ff46fbc90b4c181cc79d5 Mon Sep 17 00:00:00 2001 From: Benjamin Kiessling Date: Wed, 19 Jun 2024 14:11:40 +0200 Subject: [PATCH] Print helpful warning when manifest file is binary --- kraken/ketos/util.py | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/kraken/ketos/util.py b/kraken/ketos/util.py index 923d51da9..70bc28c16 100644 --- a/kraken/ketos/util.py +++ b/kraken/ketos/util.py @@ -32,12 +32,20 @@ def _validate_manifests(ctx, param, value): images = [] for manifest in value: - for entry in manifest.readlines(): - im_p = entry.rstrip('\r\n') - if os.path.isfile(im_p): - images.append(im_p) - else: - logger.warning('Invalid entry "{}" in {}'.format(im_p, manifest.name)) + try: + for entry in manifest.readlines(): + im_p = entry.rstrip('\r\n') + if os.path.isfile(im_p): + images.append(im_p) + else: + logger.warning('Invalid entry "{}" in {}'.format(im_p, manifest.name)) + except UnicodeDecodeError: + raise click.BadOptionUsage(param, + f'File {manifest.name} is not a text file. Please ' + 'ensure that the argument to `-t`/`-e` is a manifest ' + 'file containing paths to training data (one per ' + 'line).', + ctx=ctx) return images