Print errors when json parsing fails

Closes #258
This commit is contained in:
Ben Jackson 2020-11-28 18:04:36 +00:00
commit dd4460598a

View file

@ -91,11 +91,17 @@ class DebugSession( object ):
if not launch_config_file or not os.path.exists( launch_config_file ):
continue
with open( launch_config_file, 'r' ) as f:
database = json.loads( minify( f.read() ) )
if database:
configurations.update( database.get( 'configurations' or {} ) )
adapters.update( database.get( 'adapters' ) or {} )
try:
with open( launch_config_file, 'r' ) as f:
database = json.loads( minify( f.read() ) )
if database:
configurations.update( database.get( 'configurations' or {} ) )
adapters.update( database.get( 'adapters' ) or {} )
except json.JSONDecodeError as e:
self._logger.exception( f"Unable to read { launch_config_file }" )
utils.UserMessage( f"Unable to read { launch_config_file }: { e }",
error = True,
persist = True )
return launch_config_file, configurations
@ -115,9 +121,11 @@ class DebugSession( object ):
launch_config_file, configurations = self.GetConfigurations( adapters )
if not configurations:
utils.UserMessage( 'Unable to find any debug configurations. '
utils.UserMessage( 'Unable to find any valid debug configurations. '
'You need to tell vimspector how to launch your '
'application.' )
'application. See :messages for any errors.',
persist = True,
error = True )
return
glob.glob( install.GetGadgetDir( VIMSPECTOR_HOME ) )
@ -127,9 +135,15 @@ class DebugSession( object ):
if not gadget_config_file or not os.path.exists( gadget_config_file ):
continue
with open( gadget_config_file, 'r' ) as f:
a = json.loads( minify( f.read() ) ).get( 'adapters' ) or {}
adapters.update( a )
try:
with open( gadget_config_file, 'r' ) as f:
a = json.loads( minify( f.read() ) ).get( 'adapters' ) or {}
adapters.update( a )
except json.JSONDecodeError as e:
self._logger.exception( f'Unable to read { gadget_config_file }' )
utils.UserMessage( f"Unable to read { gadget_config_file }: { e }",
error = True,
persist = True )
if 'configuration' in launch_variables:
configuration_name = launch_variables.pop( 'configuration' )