From 6fb061f65a0b461b50a91ad6fd7910c3f4ded1ac Mon Sep 17 00:00:00 2001 From: David Pomeroy Date: Tue, 10 Oct 2023 17:24:57 +0000 Subject: [PATCH] Update schema validation error message Add detail to make schema validation error message more useful. --- lib/ramble/ramble/config.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/lib/ramble/ramble/config.py b/lib/ramble/ramble/config.py index a1b1ddfdf..5ef116104 100644 --- a/lib/ramble/ramble/config.py +++ b/lib/ramble/ramble/config.py @@ -1336,14 +1336,17 @@ def __init__(self, validation_error, data, filename=None, line=None): self.filename = filename # record this for ruamel.yaml - # construct location + # construct the location and retrieve the line that caused the error location = '' if filename: - location = '%s' % filename + location = f'{filename}' if line is not None: - location += ':%d' % line + location += f':{line}' + with open(filename, 'r') as file: + lines = file.readlines() + location += f'\n{lines[mark.line]}' - message = '%s: %s' % (location, validation_error.message) + message = f'{location}\n{validation_error}' super(ConfigError, self).__init__(message) def _get_mark(self, validation_error, data):