summaryrefslogtreecommitdiffstats
path: root/cfgv.py
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--cfgv.py9
1 files changed, 6 insertions, 3 deletions
diff --git a/cfgv.py b/cfgv.py
index 64c2380..f0b9eff 100644
--- a/cfgv.py
+++ b/cfgv.py
@@ -395,11 +395,14 @@ def load_from_filename(
if not os.path.exists(filename):
raise ValidationError(f'{filename} does not exist')
- with open(filename, encoding='utf-8') as f:
- contents = f.read()
-
with validate_context(f'File {filename}'):
try:
+ with open(filename, encoding='utf-8') as f:
+ contents = f.read()
+ except UnicodeDecodeError as e:
+ raise ValidationError(str(e))
+
+ try:
data = load_strategy(contents)
except Exception as e:
raise ValidationError(str(e))