summary refs log tree commit diff
path: root/synapse/config/_util.py
diff options
context:
space:
mode:
authorPatrick Cloke <patrickc@matrix.org>2020-12-15 08:23:14 -0500
committerPatrick Cloke <patrickc@matrix.org>2020-12-15 08:23:14 -0500
commit33a349df91a459435e33c5676bb40c8690492f65 (patch)
tree475c01ad2e72c69665974a8d4917e4095c3f280c /synapse/config/_util.py
parentMerge branch 'release-v1.24.0' of github.com:matrix-org/synapse into matrix-o... (diff)
parentFix startup failure with localdb_enabled: False (#8937) (diff)
downloadsynapse-33a349df91a459435e33c5676bb40c8690492f65.tar.xz
Merge branch 'develop' into matrix-org-hotfixes
Diffstat (limited to 'synapse/config/_util.py')
-rw-r--r--synapse/config/_util.py35
1 files changed, 24 insertions, 11 deletions
diff --git a/synapse/config/_util.py b/synapse/config/_util.py

index c74969a977..1bbe83c317 100644 --- a/synapse/config/_util.py +++ b/synapse/config/_util.py
@@ -38,14 +38,27 @@ def validate_config( try: jsonschema.validate(config, json_schema) except jsonschema.ValidationError as e: - # copy `config_path` before modifying it. - path = list(config_path) - for p in list(e.path): - if isinstance(p, int): - path.append("<item %i>" % p) - else: - path.append(str(p)) - - raise ConfigError( - "Unable to parse configuration: %s at %s" % (e.message, ".".join(path)) - ) + raise json_error_to_config_error(e, config_path) + + +def json_error_to_config_error( + e: jsonschema.ValidationError, config_path: Iterable[str] +) -> ConfigError: + """Converts a json validation error to a user-readable ConfigError + + Args: + e: the exception to be converted + config_path: the path within the config file. This will be used as a basis + for the error message. + + Returns: + a ConfigError + """ + # copy `config_path` before modifying it. + path = list(config_path) + for p in list(e.path): + if isinstance(p, int): + path.append("<item %i>" % p) + else: + path.append(str(p)) + return ConfigError(e.message, path)