HumanBrainProject / fairgraph

High-level Python API for the EBRAINS Knowledge Graph
Apache License 2.0
10 stars 6 forks source link

More precise exception handling for unserializable values #83

Closed archgogo closed 1 week ago

archgogo commented 1 year ago

When trying to save a tissue sample with

new_ts.save(fg_client)

I often get a value error if any of the fields are incorrect (see below). It would greatly help me when debugging if fairgraph would tell me specifically which fields are incorrect so that I may fix them. Thank you in advance

File ~\anaconda3\lib\site-packages\fairgraph\fields.py:275, in <listcomp>(.0)
    273 if isinstance(value, (list, tuple)):
    274     if self.multiple or self.error_handling != ErrorHandling.error:
--> 275         value = [serialize_single(item) for item in value]
    276         if len(value) == 1:
    277             return value[0]

File ~\anaconda3\lib\site-packages\fairgraph\fields.py:271, in Field.serialize.<locals>.serialize_single(value)
    269     return None
    270 else:
--> 271     raise ValueError("don't know how to serialize this value")

ValueError: don't know how to serialize this value
archgogo commented 1 year ago

In this case the issue wasnt actually that any of the fields were incorrect, but that the instance already existed on the knowledge graph (I was rerunning the code). If possible it would be useful for the error to indicate this. Thank you

apdavison commented 1 week ago

The error message is now of the form:

ValueError("fairgraph cannot serialize a value of type <class 'someclass'> (for property 'some_property_name')")

Without more of the error traceback, I cannot diagnose the problem with the instance already existing.