Provide more specific exceptions/errors than just value_error
- Dominant language
- Python
- Stars
- 7
- Forks
- 15
- PR merge metrics
- No merged PRs in 30d
Description
ATM we use ValueError as a generic exception for when value is not the one we like to have
```shell
❯ git grep 'raise ValueError'
dandischema/datacite.py: raise ValueError(
dandischema/digests/dandietag.py: raise ValueError("File is larger than the S3 maximum object size.")
dandischema/digests/dandietag.py: raise ValueError("Not all part hashes submitted")
dandischema/digests/dandietag.py: raise ValueError("Digesting new part when current part is not complete")
dandischema/digests/dandietag.py: raise ValueError("Partial update extended past end of file")
dandischema/digests/zarr.py: raise ValueError(f"Cannot parse directory digest {digest}")
dandischema/digests/zarr.py: raise ValueError("Not found")
dandischema/digests/zarr.py: raise ValueError("Cannot compute a Zarr checksum for an empty directory")
dandischema/metadata.py: raise ValueError("Provided object has no known schemaKey")
dandischema/metadata.py: raise ValueError(
dandischema/metadata.py: raise ValueError(
dandischema/metadata.py: raise ValueError(f"Current target schemas: {ALLOWED_TARGET_SCHEMAS}.")
dandischema/metadata.py: raise ValueError(f"Current input schemas supported: {ALLOWED_INPUT_SCHEMAS}.")
dandischema/metadata.py: raise ValueError(f"Cannot migrate from {schema_version} to lower {to_version}.")
dandischema/metadata.py: raise ValueError("Cannot auto migrate. SchemaKey missing")
dandischema/metadata.py: raise ValueError("Provided metadata has no schema version")
dandischema/metadata.py: raise ValueError(
dandischema/models.py: raise ValueError(f"Could not generate a klass or items from {data}")
dandischema/models.py: raise ValueError(
dandischema/models.py: raise ValueError(
dandischema/models.py: raise ValueError("Both identifier and url cannot be None")
dandischema/models.py: raise ValueError(
dandischema/models.py: raise ValueError("At least one contributor must have role ContactPerson")
dandischema/models.py: raise ValueError("A zarr asset must have a zarr checksum.")
dandischema/models.py: raise ValueError("Digest cannot have both etag and zarr checksums.")
dandischema/models.py: raise ValueError(
dandischema/models.py: raise ValueError(
dandischema/models.py: raise ValueError("A non-zarr asset must have a dandi-etag.")
dandischema/models.py: raise ValueError("Digest cannot have both etag and zarr checksums.")
dandischema/models.py: raise ValueError(
dandischema/models.py: raise ValueError(
dandischema/models.py: raise ValueError("A non-zarr asset must have a sha2_256.")
dandischema/models.py: raise ValueError(
dandischema/tests/test_models.py: raise ValueError(f"{qname},{klass} already exists {qnames[qname]}")
dandischema/utils.py: raise ValueError(r"Version must be well formed: \d+\.\d+\.\d+")
```
and some of them in particular whenever we indicate that the value is required! (not sure why we make it optional then to start with? didn't check)
```
❯ git grep 'must have a' | grep -v appropriate
dandischema/models.py: raise ValueError("A zarr asset must have a zarr checksum.")
dandischema/models.py: raise ValueError("A non-zarr asset must have a dandi-etag.")
dandischema/models.py: raise ValueError("A non-zarr asset must have a sha2_256.")
dandischema/tests/test_models.py: "A non-zarr asset must have a sha2_256." in el["msg"]
dandischema/tests/test_models.py: "A zarr asset must have a zarr checksum." in val
dandischema/tests/test_models.py: "A zarr asset must have a zarr checksum." in val
```
That results that whenever we catch ValidationError in dandi-cli we cannot really tell if it is the error that value is completely absent or something else without matching a message (unreliable, shouldn't be done):
```
*(Pdb) p e.errors()
[{'loc': ('digest',), 'msg': 'A zarr asset must have a zarr checksum.', 'type': 'value_error'}]
```
I guess (didn't check) if we specialize to other types of derived from ValueError exceptions, like `MissingValue(ValueError)` we might get `'type': 'missing_value'` ?
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.