Open yarikoptic opened 1 year ago
is there a specific list you would like that you would do something programmatic with (i.e. the semantics of typing are useful to you somewhere)? if it's primarily for humans, we should just go through the messages and improve them. also if you simply want to know its from dandischema, we can create a special ValueError
. i think subtyping exceptions creates technical debt, unless it is useful in some form.
So far I see clear distinction only for MissingValue
(it was not even provided! first thing to look at). yet to see in detail/compare to how it looks like whenever it is really missing according to pydantic schema itself.
Then useful to harmonize to see how it looks like whenever value is not corresponding to how pydantic reacts that value is not satisfying what it expects.
As for why -- we are taking that type
as a part of a ValidationResult
ID. We later might group based on what is missing vs what is entered but incorrectly etc. So it then would become not only about display but also about being able to tell one from another.
Related to https://github.com/dandi/dandi-archive/pull/1490.
@yarikoptic - most of the exceptions come directly from pydantic. are you only saying to have a MissingValueError
or match it to pydantic's validationerror
, which is based on message. or create a whole scheme of exceptions. if that latter, please describe which pydantic message should map to what exception.
What matters for me is that 'type': 'value_error'
within ValidationError.errors()
returns. I want it to be missing_value_error
. I don't know really what it entails within dandi-schema/pedantic, but I thought the first step could be to derive custom exception.
With https://github.com/dandi/dandi-archive/pull/1490 by @danlamanna in mind, I would say it is worth creating base class of DandiSchemaError, and sub/multi-class
class DandiValueError(ValueError, DandiSchemaError):
pass
class DandiMissingValueError(DandiValueError):
pass
and throughout dandi-schema code base use DandiValueError
instead of plain ValueError
so anyone catching exceptions from us could tell some other ValueError etc apart from the ones we raise.
can we just leave it as pydantic? i can replace where we generate ValueError
with a pydantic ValidationError
object.
In [12]: try:
...: Dandiset()
...: except ValidationError as e:
...: print(e.__repr__())
...:
ValidationError(model='Dandiset', errors=[{'loc': ('id',), 'msg': 'field required', 'type': 'value_error.missing'}, {'loc': ('name',), 'msg': 'field required', 'type': 'value_error.missing'}, {'loc': ('description',), 'msg': 'field required', 'type': 'value_error.missing'}, {'loc': ('contributor',), 'msg': 'field required', 'type': 'value_error.missing'}, {'loc': ('license',), 'msg': 'field required', 'type': 'value_error.missing'}, {'loc': ('identifier',), 'msg': 'field required', 'type': 'value_error.missing'}, {'loc': ('citation',), 'msg': 'field required', 'type': 'value_error.missing'}, {'loc': ('assetsSummary',), 'msg': 'field required', 'type': 'value_error.missing'}, {'loc': ('manifestLocation',), 'msg': 'field required', 'type': 'value_error.missing'}, {'loc': ('version',), 'msg': 'field required', 'type': 'value_error.missing'}])
we will have to also decide what we do with both JSON validation and pydantic validation, which are both created in the validation function.
For my current need having 'value_error.missing'
I believe would suffice.
ATM we use ValueError as a generic exception for when value is not the one we like to have
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)
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):
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'
?