Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[enhancement] Issue a more compact message when JSON schema validation fails #3314

Merged
merged 1 commit into from
Nov 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions reframe/core/config.py
Original file line number Diff line number Diff line change
@@ -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'])
6 changes: 5 additions & 1 deletion reframe/core/exceptions.py
Original file line number Diff line number Diff line change
@@ -8,6 +8,7 @@
#

import inspect
import jsonschema
import os

import reframe
@@ -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

1 change: 1 addition & 0 deletions reframe/frontend/autodetect.py
Original file line number Diff line number Diff line change
@@ -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
4 changes: 2 additions & 2 deletions reframe/frontend/reporting/__init__.py
Original file line number Diff line number Diff line change
@@ -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)

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