Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Error message for incompatible constructor options #214

Merged
merged 2 commits into from
Mar 3, 2025

Conversation

dnlbauer
Copy link
Contributor

The constructor arguments init and passing a jsonld dictionary as source are mutually exclusive.

At the moment, when passing a dict containing JSONLD as source to the contructor and setting init=True, a cryptic error message is shown:

from rocrate.rocrate import ROCrate
crate = ROCrate({"@context": "http://example.com", "@graph": []}, init=True)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/dbauer/projects/ro-crate-py/rocrate/rocrate.py", line 94, in __init__
    self.__init_from_tree(source, gen_preview=gen_preview)
  File "/home/dbauer/projects/ro-crate-py/rocrate/rocrate.py", line 101, in __init_from_tree
    top_dir = Path(top_dir)
  File "/home/dbauer/.local/share/uv/python/cpython-3.9.21-linux-x86_64-gnu/lib/python3.9/pathlib.py", line 1082, in __new__
    self = cls._from_parts(args, init=False)
  File "/home/dbauer/.local/share/uv/python/cpython-3.9.21-linux-x86_64-gnu/lib/python3.9/pathlib.py", line 707, in _from_parts
    drv, root, parts = self._parse_args(args)
  File "/home/dbauer/.local/share/uv/python/cpython-3.9.21-linux-x86_64-gnu/lib/python3.9/pathlib.py", line 691, in _parse_args
    a = os.fspath(a)
TypeError: expected str, bytes or os.PathLike object, not dict

This PR replaces this error with a message telling the user what the issue actually is:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/dbauer/projects/ro-crate-py/rocrate/rocrate.py", line 95, in __init__
    raise ValueError("parameter init is not compatible with a JsonLD source")
ValueError: parameter init is not compatible with a JsonLD source

@simleo simleo merged commit 61eb7cb into ResearchObject:master Mar 3, 2025
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants