Skip to content
This repository was archived by the owner on Aug 16, 2021. It is now read-only.
This repository was archived by the owner on Aug 16, 2021. It is now read-only.

First-class support to pass multiple Errors upstream #293

Open
@ksf

Description

@ksf

As motivating example, let's say I want to create a file and pass its path to a child process, so that it can talk to me via unix sockets, all functions returning Results:

let sock_path = create_socket()?;
let res = spawn_wait_child(sock_path);
delete_socket(sock_path)?;
return res;

Now suppose that a couple of umounts happen directly after create_socket, causing first the child executable to not be found, and then delete_socket failing, too: The user will never see the error arising from spawn_wait_child. Ideally, what I'd want to write is something like this:

let sock_path = create_socket()?;
let res = spawn_wait_child(sock_path);
let cleanup = delete_socket(sock_path);
return res.as_well_as(cleanup);

If either res or cleanup fails we get the respective single error, if both fail we get something like

myprog: multiple errors: 
    spawn: fooprog: No such file or directory
    delete: barsock: No such file or directory

Glancing at the API, it seems to me that one option would be to change cause and find_root_cause to return iterators instead of an option / a single value, leading to a tree of causes.

(Actually, that implementation is a better semantic match in situations where there's multiple ways in which an operation could succeed (e.g. multiple config file paths being known), each being tried, and all of them failing. I don't think it's necessary to distinguish "one of" vs. "all of" for error reporting purposes, though... and also having downcast_ref etc. return iterators smells like overkill).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions