haystack
haystack copied to clipboard
Make `DeserializationError` error message more descriptive
When creating a new custom component that uses a Haystack Secret in it's init method I forgot to create explicit to_dict and from_dict methods to handle the serialization of the secret. For example,
@component
class CustomComponent:
def __init__(self, api_key: Secret = Secret.from_env_var("API_KEY")):
self.api_key = api_key
@component.output_types(answers=List[GeneratedAnswer])
def run(self, query: str) -> Dict[str, List[GeneratedAnswer]]:
pass
then when loading this component from a yaml file definition of a pipeline I got this error message
raise DeserializationError(
haystack.core.errors.DeserializationError: Error while unmarshalling serialized pipeline data. This is usually caused by malformed or invalid syntax in the serialized representation.
Would it be possible to include in the DeserializationError error message some additional information like the name of the Component that failed to deserialize?
I realize that in the stack trace I get more info like this
yaml.constructor.ConstructorError: could not determine a constructor for the tag 'tag:yaml.org,2002:python/object:haystack.utils.auth.EnvVarSecret'
in "<unicode string>", line 4, column 16:
api_key: !!python/object:haystack.utils.a ...
but this doesn't tell me which component caused the issue which would be helpful.
I simulated this error message by doing this
cc = CustomComponent()
pipe = Pipeline()
pipe.add_component("custom", cc)
test = Pipeline().loads(pipe.dumps())