File tree Expand file tree Collapse file tree 2 files changed +10
-2
lines changed Expand file tree Collapse file tree 2 files changed +10
-2
lines changed Original file line number Diff line number Diff line change 4949 QGIST_CONFIG_FLD ,
5050 )
5151from .error import (
52+ QgistConfigFormatError ,
5253 QgistConfigKeyError ,
5354 QgistTypeError ,
5455 QgistValueError ,
@@ -107,7 +108,11 @@ def __init__(self, fn):
107108 if not os .path .isfile (fn ):
108109 raise QgistValueError (translate ('global' , '"fn" must be a file. (config)' ))
109110 with open (fn , 'r' , encoding = 'utf-8' ) as f :
110- self ._data = json .loads (f .read ())
111+ data = f .read ()
112+ try :
113+ self ._data = json .loads (data )
114+ except :
115+ raise QgistConfigFormatError (translate ('global' , 'Config does not contain valid JSON. (config)' ))
111116 if not isinstance (self ._data , dict ):
112117 raise QgistTypeError (translate ('global' , 'Configuration data must be a dict. (config)' ))
113118
@@ -196,7 +201,7 @@ def import_config(fn):
196201 try :
197202 value = json .loads (raw )
198203 except :
199- raise QgistValueError (translate ('global' , '"fn" does not contain valid JSON. (config import)' ))
204+ raise QgistConfigFormatError (translate ('global' , '"fn" does not contain valid JSON. (config import)' ))
200205
201206 return value
202207
Original file line number Diff line number Diff line change 3131class QgistAttributeError (AttributeError ):
3232 pass
3333
34+ class QgistConfigFormatError (KeyError ):
35+ pass
36+
3437class QgistConfigKeyError (KeyError ):
3538 pass
3639
You can’t perform that action at this time.
0 commit comments