Skip to content

Commit 017a22a

Browse files
committed
Better error handling and error message
Signed-off-by: Chin Yeung Li <[email protected]>
1 parent 0a99b1d commit 017a22a

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

src/attributecode/model.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1004,6 +1004,11 @@ def load(self, location):
10041004
loc = add_unc(loc)
10051005
with io.open(loc, encoding='utf-8', errors='replace') as txt:
10061006
input_text = txt.read()
1007+
if not input_text:
1008+
msg = 'ABOUT file is empty: %(location)r'
1009+
errors.append(Error(CRITICAL, msg % locals()))
1010+
self.errors = errors
1011+
return errors
10071012
# The 'Yes' and 'No' will be converted to 'True' and 'False' in the yaml.load()
10081013
# Therefore, we need to wrap the original value in quote to prevent
10091014
# the conversion
@@ -1027,8 +1032,11 @@ def load(self, location):
10271032
errs = self.load_dict(data, base_dir, running_inventory=running_inventory)
10281033
errors.extend(errs)
10291034
except Exception as e:
1030-
trace = traceback.format_exc()
1031-
msg = 'Cannot load invalid ABOUT file: %(location)r: %(e)r\n%(trace)s'
1035+
# The trace is good for debugging, but probably not good for user to
1036+
# see the traceback message
1037+
#trace = traceback.format_exc()
1038+
#msg = 'Cannot load invalid ABOUT file: %(location)r: %(e)r\n%(trace)s'
1039+
msg = 'Cannot load invalid ABOUT file: %(location)r: %(e)r'
10321040
errors.append(Error(CRITICAL, msg % locals()))
10331041

10341042
self.errors = errors

0 commit comments

Comments
 (0)