I’m currently experimenting with the failure crate and am trying to integrate it’s methodologies into my codebase.
As per the wiki page about patterns I’m trying to construct a pattern that fits my own case.
Basically, my code could be split up into a few levels of interaction with my main object, which is a container of services;
Methods consuming the container and executing one or more methods of level 2. Ownership of the container is passed down and is returned by these methods on success.
Methods (also) consuming the container and executing specific methods for each contained service. Ownership of the container is returned by these methods on success. Operations for multiple services are executed so the returned error is not specific to one ‘domain’. I suppose my Err type here already becomes
Methods manipulating data contained by the services. At this level these operations fall within one ‘domain’ and returned errors are specific Custom Fail Types.
My exact issue is that I want to ‘bolt on’ the container object when cascading an error from level 3 up to level 1 (within level 2). Effectively returning ownership of the object in both Ok and Err cases.
So far I thought a custom Error type and Errorkind, containing variants for each level 3 custom fail types, is the way to go. This type would then be used for Err within level 1 and 2.
However this doesn’t feel idiomatic since I have to keep the variants updated with each custom fail type (not forward compatible).
Are there idiomatic implementations that tackled returning errors which include consumed values?