File tree Expand file tree Collapse file tree 2 files changed +16
-4
lines changed
Expand file tree Collapse file tree 2 files changed +16
-4
lines changed Original file line number Diff line number Diff line change @@ -43,9 +43,10 @@ def _load_profile(base_dir):
4343 return {}
4444 except json .JSONDecodeError as exc :
4545 logging .error ("Failed to parse %s: %s" , path , exc )
46+ raise
4647 except OSError as exc :
4748 logging .error ("Unable to read %s: %s" , path , exc )
48- return {}
49+ raise
4950
5051
5152def _profile_sections (profile ):
@@ -198,7 +199,15 @@ def generate_invoice(buffer, invoice_data):
198199
199200def main ():
200201 base_dir = os .path .dirname (os .path .abspath (__file__ ))
201- profile = _load_profile (base_dir )
202+ try :
203+ profile = _load_profile (base_dir )
204+ except json .JSONDecodeError as exc :
205+ print (f"Invalid institution profile: { exc } " , file = sys .stderr )
206+ sys .exit (1 )
207+ except OSError as exc :
208+ print (f"Unable to read institution profile: { exc } " , file = sys .stderr )
209+ sys .exit (1 )
210+
202211 invoice_data = json .load (sys .stdin )
203212
204213 # Fill in profile-based sections if not provided
Original file line number Diff line number Diff line change 33import unittest
44from unittest import mock
55import logging
6+ import json
67
78from invoice import _load_profile
89
@@ -18,14 +19,16 @@ def test_invalid_json_logs_error(self):
1819 with open (path , "w" , encoding = "utf-8" ) as fh :
1920 fh .write ("{invalid" )
2021 with self .assertLogs (level = "ERROR" ) as cm :
21- self .assertEqual (_load_profile (td ), {})
22+ with self .assertRaises (json .JSONDecodeError ):
23+ _load_profile (td )
2224 self .assertIn ("Failed to parse" , cm .output [0 ])
2325
2426 def test_os_error_logs_error (self ):
2527 with tempfile .TemporaryDirectory () as td :
2628 with mock .patch ("builtins.open" , side_effect = PermissionError ("denied" )):
2729 with self .assertLogs (level = "ERROR" ) as cm :
28- self .assertEqual (_load_profile (td ), {})
30+ with self .assertRaises (OSError ):
31+ _load_profile (td )
2932 self .assertIn ("Unable to read" , cm .output [0 ])
3033
3134
You can’t perform that action at this time.
0 commit comments