Skip to content

False "not UTF-8 encoded" issue in metadata-only validation against the ro-crate-1.2 profile #192

Description

@alexhambley

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

  1. In metadata-only mode, ROCrate.from_metadata_dict creates ROCrate(URI("./"))
  2. 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).
  3. 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.
  4. 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions