diff --git a/swh/model/identifiers.py b/swh/model/identifiers.py --- a/swh/model/identifiers.py +++ b/swh/model/identifiers.py @@ -728,22 +728,19 @@ def check_namespace(self, attribute, value): if value != SWHID_NAMESPACE: raise ValidationError( - "Wrong format: only supported namespace is '%s'" % SWHID_NAMESPACE + f"Wrong format: Supported namespace is '{SWHID_NAMESPACE}'" ) @scheme_version.validator def check_scheme_version(self, attribute, value): if value != SWHID_VERSION: - raise ValidationError( - "Wrong format: only supported version is %d" % SWHID_VERSION - ) + raise ValidationError(f"Wrong format: Supported version is {SWHID_VERSION}") @object_type.validator def check_object_type(self, attribute, value): if value not in _object_type_map: - raise ValidationError( - "Wrong input: Supported types are %s" % (list(_object_type_map.keys())) - ) + supported_types = ", ".join(list(_object_type_map.keys())) + raise ValidationError(f"Wrong input: Supported types are {supported_types}") @object_id.validator def check_object_id(self, attribute, value): @@ -823,7 +820,22 @@ swhid_data = swhid_parts.pop(0).split(":") if len(swhid_data) != 4: - raise ValidationError("Wrong format: There should be 4 mandatory values") + raise ValidationError( + """Wrong format: The supported format should be: + ::= "swh" ":" ":" ":" ; + ::= "1" ; + ::= + "snp" (* snapshot *) + | "rel" (* release *) + | "rev" (* revision *) + | "dir" (* directory *) + | "cnt" (* content *) + ; + ::= 40 * ; (* intrinsic object id, as hex-encoded SHA1 *) + ::= "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9" ; + ::= | "a" | "b" | "c" | "d" | "e" | "f" ; +""" + ) # Checking for parsing errors _ns, _version, _type, _id = swhid_data @@ -834,7 +846,13 @@ break if not _id: - raise ValidationError("Wrong format: Identifier should be present") + raise ValidationError( + """Wrong format: should be provided: + ::= 40 * ; (* intrinsic object id, as hex-encoded SHA1 *) + ::= "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9" ; + ::= | "a" | "b" | "c" | "d" | "e" | "f" ; +""" + ) _metadata = {} for part in swhid_parts: @@ -842,7 +860,23 @@ key, val = part.split("=") _metadata[key] = val except Exception: - msg = "Contextual data is badly formatted, form key=val expected" + msg = """Wrong format: contextual data should be of form: + := ";" [ ] ; + ::= + + | + ; + ::= + + | + | + | + ; + ::= "origin" "=" ; + ::= "visit" "=" ; + ::= "anchor" "=" ; + ::= "path" "=" ; +""" raise ValidationError(msg) return SWHID( _ns,