Skip to content

Commit 624534c

Browse files
committed
Improved validation error messages for module names
Signed-off-by: Ole Herman Schumacher Elgesem <ole.elgesem@northern.tech>
1 parent 55c5cc1 commit 624534c

1 file changed

Lines changed: 13 additions & 1 deletion

File tree

cfbs/validate.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,10 @@ def validate_module_name_content(name):
227227
r = "[a-z][a-z0-9]*(-[a-z0-9]+)*"
228228
proper_name = name
229229

230+
if is_module_local(name) or is_module_absolute(name):
231+
# If one of these are true, the other must be false
232+
assert is_module_absolute(name) != is_module_local(name)
233+
230234
if is_module_local(name):
231235
if not name.startswith("./"):
232236
raise CFBSValidationError(name, "Local module names should begin with `./`")
@@ -270,10 +274,18 @@ def validate_module_name_content(name):
270274
"Module name proper is empty",
271275
)
272276

277+
if proper_name[0] not in "abcdefghijklmnopqrstuvwxyz":
278+
raise CFBSValidationError(
279+
name,
280+
"Module name must start with a lowercase ASCII letter ('{}' starts with '{}')".format(
281+
proper_name, proper_name[0]
282+
),
283+
)
284+
273285
if not re.fullmatch(r, proper_name):
274286
raise CFBSValidationError(
275287
name,
276-
"Module name contains illegal characters (only lowercase ASCII alphanumeric characters are legal)",
288+
"Module name contains illegal characters (only lowercase ASCII alphanumeric characters and single dash separators are allowed)",
277289
)
278290

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

0 commit comments

Comments
 (0)