Skip to content

Commit ada9a3c

Browse files
committed
CFE-4667: Improve error message from cfbs about illegal characters in module names
Ticket: CFE-4667
1 parent 954aef4 commit ada9a3c

1 file changed

Lines changed: 11 additions & 3 deletions

File tree

cfbs/validate.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -274,18 +274,26 @@ def validate_module_name_content(name):
274274
"Module name proper is empty",
275275
)
276276

277+
# build a suggested fix for the module name:
278+
suggested_proper_name = re.sub(r"[^a-z0-9]+", "-", proper_name.lower()).strip("-")
279+
if suggested_proper_name and re.fullmatch(r, suggested_proper_name):
280+
suggestion = " Consider renaming it to '{}'.".format(suggested_proper_name)
281+
else:
282+
suggestion = ""
283+
277284
if proper_name[0] not in "abcdefghijklmnopqrstuvwxyz":
278285
raise CFBSValidationError(
279286
name,
280-
"Module name must start with a lowercase ASCII letter ('{}' starts with '{}')".format(
281-
proper_name, proper_name[0]
287+
"Module name must start with a lowercase ASCII letter ('{}' starts with '{}'){}".format(
288+
proper_name, proper_name[0], suggestion
282289
),
283290
)
284291

285292
if not re.fullmatch(r, proper_name):
286293
raise CFBSValidationError(
287294
name,
288-
"Module name contains illegal characters (only lowercase ASCII alphanumeric characters and single dash separators are allowed)",
295+
"Module name contains illegal characters (only lowercase ASCII alphanumeric characters and single dash separators are allowed)"
296+
+ suggestion,
289297
)
290298

291299
log.debug("Successfully validated name of module %s" % name)

0 commit comments

Comments
 (0)