From ada9a3cd0f84c7f01a3ea348a243ea0f4fd11d6a Mon Sep 17 00:00:00 2001 From: Sara Thon Date: Wed, 10 Jun 2026 10:58:51 +0200 Subject: [PATCH] CFE-4667: Improve error message from cfbs about illegal characters in module names Ticket: CFE-4667 --- cfbs/validate.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/cfbs/validate.py b/cfbs/validate.py index 537c2ae8..236935a5 100644 --- a/cfbs/validate.py +++ b/cfbs/validate.py @@ -274,18 +274,26 @@ def validate_module_name_content(name): "Module name proper is empty", ) + # build a suggested fix for the module name: + suggested_proper_name = re.sub(r"[^a-z0-9]+", "-", proper_name.lower()).strip("-") + if suggested_proper_name and re.fullmatch(r, suggested_proper_name): + suggestion = " Consider renaming it to '{}'.".format(suggested_proper_name) + else: + suggestion = "" + if proper_name[0] not in "abcdefghijklmnopqrstuvwxyz": raise CFBSValidationError( name, - "Module name must start with a lowercase ASCII letter ('{}' starts with '{}')".format( - proper_name, proper_name[0] + "Module name must start with a lowercase ASCII letter ('{}' starts with '{}'){}".format( + proper_name, proper_name[0], suggestion ), ) if not re.fullmatch(r, proper_name): raise CFBSValidationError( name, - "Module name contains illegal characters (only lowercase ASCII alphanumeric characters and single dash separators are allowed)", + "Module name contains illegal characters (only lowercase ASCII alphanumeric characters and single dash separators are allowed)" + + suggestion, ) log.debug("Successfully validated name of module %s" % name)