Summary
When validating with metadata_only=True / metadata_dict=... against the ro-crate-1.2 profile, the validator reports:
ro-crate-1.2_3.1: RO-Crate file descriptor "ro-crate-metadata.json" is not UTF-8 encoded
This is the case when the submitted metadata is perfectly valid.
This is because the check is reading the file descriptor from disk, but in metadata-only mode there is no file on disk, so a FileNotFoundError is raised and then reported as an encoding failure. Additionally, whether validation passes or fails actually depends on whether an unrelated ro-crate-metadata.json happens to exist under the validating process's current working directory (CWD).
Issue
- In metadata-only mode,
ROCrate.from_metadata_dict creates ROCrate(URI("./"))
- The
ro-crate-1.2 profile's FileDescriptorEncodingCheck has no metadata-only guard. FileDescriptorExistence.test_existence, for example, does, and returns true early on context.settings.metadata_only).
- It calls
get_file_content(Path(context.ro_crate.metadata_descriptor_id), binary_mode=True). ROCrateLocalFolder.metadata_descriptor_id then rglobs the CWD for *ro-crate-metadata.json and falls back to "ro-crate-metadata.json" when nothing matches; get_file_content then raises FileNotFoundError.
- The check's
except Exception converts that into the "is not UTF-8 encoded" issue.
Suggested Fix
- I would skip the check in metadata-only mode like the class above;
- I would try and narrow the exception handling to avoid the "not UTF-8 encoded" issue for a FileNotFoundError;
Context
I was looking at the PR in eScienceLab/RO-Crate-Validation-Service#210, where a five-safes profile update updated from ro-crate-1.1 to ro-crate-1.2.
Summary
When validating with
metadata_only=True/metadata_dict=...against thero-crate-1.2profile, the validator reports:This is the case when the submitted metadata is perfectly valid.
This is because the check is reading the file descriptor from disk, but in metadata-only mode there is no file on disk, so a
FileNotFoundErroris raised and then reported as an encoding failure. Additionally, whether validation passes or fails actually depends on whether an unrelatedro-crate-metadata.jsonhappens to exist under the validating process's current working directory (CWD).Issue
ROCrate.from_metadata_dictcreatesROCrate(URI("./"))ro-crate-1.2profile'sFileDescriptorEncodingCheckhas no metadata-only guard.FileDescriptorExistence.test_existence, for example, does, and returns true early oncontext.settings.metadata_only).get_file_content(Path(context.ro_crate.metadata_descriptor_id), binary_mode=True).ROCrateLocalFolder.metadata_descriptor_idthenrglobs the CWD for*ro-crate-metadata.jsonand falls back to"ro-crate-metadata.json"when nothing matches;get_file_contentthen raisesFileNotFoundError.except Exceptionconverts that into the "is not UTF-8 encoded" issue.Suggested Fix
Context
I was looking at the PR in eScienceLab/RO-Crate-Validation-Service#210, where a five-safes profile update updated from ro-crate-1.1 to ro-crate-1.2.