From b46102359331a15cb0a4e827c833df3a04c0417a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Kl=C3=B6tzke?= Date: Tue, 10 Feb 2026 21:46:56 +0100 Subject: [PATCH] input: improve setting/property validation errors The validation of internal settings already produces proper schema exceptions if errors are found. We must not cat these exceptions but propagate them, though. Likewise, allow external plugins to throw schema.SchemaError exceptions. In case the validate() function returns false, throw the exception ourselves. Fixes #696. --- pym/bob/input.py | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/pym/bob/input.py b/pym/bob/input.py index 729a2089..08a3e70d 100644 --- a/pym/bob/input.py +++ b/pym/bob/input.py @@ -376,11 +376,8 @@ def merge(self, other): self.__updater(self.__schema.validate(other) if self.__mangle else other) def validate(self, data): - try: - self.__schema.validate(data) - return True - except schema.SchemaError: - return False + self.__schema.validate(data) + return True def Scm(spec, env, overrides, recipeSet): def _substitute(k, v): @@ -3252,6 +3249,14 @@ def validate(self, data): raise schema.SchemaError(None, "Int value must not be negative") return data +def wrapValidator(validator, message): + def wrapper(data): + if validator(data): + return True + else: + raise schema.SchemaError(message) + return wrapper + class LayersConfig: def __init__(self): @@ -4251,8 +4256,9 @@ def __createSchemas(self): schema.Optional('packageAuditFiles') : AuditFilesValidator("packageAuditFiles"), } for (name, prop) in self.__properties.items(): - classSchemaSpec[schema.Optional(name)] = schema.Schema(prop.validate, - error="property '"+name+"' has an invalid type") + classSchemaSpec[schema.Optional(name)] = schema.Schema( + wrapValidator(prop.validate, + "property '"+name+"' has an invalid type")) self.__classSchema = (schema.Schema(classSchemaSpec), self.__pluginPropDeps) @@ -4267,8 +4273,9 @@ def __createSchemas(self): schema.Optional('require') : schema.Schema([str]), } for (name, setting) in self.__settings.items(): - userConfigSchemaSpec[schema.Optional(name)] = schema.Schema(setting.validate, - error="setting '"+name+"' has an invalid type") + userConfigSchemaSpec[schema.Optional(name)] = schema.Schema( + wrapValidator(setting.validate, + "setting '"+name+"' has an invalid type")) self.__userConfigSchema = (schema.Schema(userConfigSchemaSpec), self.__pluginSettingsDeps)