Skip to content

Commit

Permalink
Merge pull request #3314 from vkarak/enhancement/compact-config-error
Browse files Browse the repository at this point in the history
[enhancement] Issue a more compact message when JSON schema validation fails
  • Loading branch information
vkarak authored Nov 12, 2024
2 parents d7b8a1e + a538b71 commit 854c5fb
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 11 deletions.
6 changes: 4 additions & 2 deletions reframe/core/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -447,8 +447,10 @@ def validate(self):
try:
jsonschema.validate(site_config, self._schema)
except jsonschema.ValidationError as e:
raise ConfigError(f"could not validate configuration files: "
f"'{self._sources}'") from e
getlogger().debug(str(e))
sources = ', '.join(f'`{f}`' for f in self._sources)
raise ConfigError('could not validate configuration files: '
f'{sources}') from e

def _warn_variables(config, opt_path):
opt_path = '/'.join(opt_path + ['variables'])
Expand Down
6 changes: 5 additions & 1 deletion reframe/core/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#

import inspect
import jsonschema
import os

import reframe
Expand Down Expand Up @@ -54,7 +55,10 @@ def message(self):
def __str__(self):
ret = self._message or ''
if self.__cause__ is not None:
ret += ': ' + str(self.__cause__)
if isinstance(self.__cause__, jsonschema.ValidationError):
ret += ': ' + self.__cause__.message
else:
ret += ': ' + str(self.__cause__)

return ret

Expand Down
1 change: 1 addition & 0 deletions reframe/frontend/autodetect.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ def _load_info(filename, schema=None):
)
return {}
except jsonschema.ValidationError as e:
getlogger().debug(str(e))
raise ConfigError(
f'could not validate meta-config file {filename!r}'
) from e
Expand Down
4 changes: 2 additions & 2 deletions reframe/frontend/reporting/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,12 +215,12 @@ def _restore_session(filename):
except KeyError:
found_ver = 'n/a'

getlogger().verbose(f'JSON validation error: {e}')
getlogger().debug(str(e))
raise ReframeError(
f'failed to validate report {filename!r}: {e.args[0]} '
f'(check report data version: required {DATA_VERSION}, '
f'found: {found_ver})'
) from None
) from e

return _RestoredSessionInfo(report)

Expand Down
6 changes: 0 additions & 6 deletions unittests/resources/config/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,12 +226,6 @@ def hostname():
'modules': ['PrgEnv-cray'],
'features': ['cxx14', 'mpi'],
},
{
'name': 'builtin',
'cc': 'cc',
'cxx': '',
'ftn': ''
},
{
'name': 'e0',
'modules': ['m0']
Expand Down

0 comments on commit 854c5fb

Please sign in to comment.