Skip to content

Sources bug? #39

@dpc

Description

@dpc

I have:

error_set! {
    // ...

    ConfigError := {
        #[display("Not initialized: .config/selfci/{} not found", constants::CONFIG_FILENAME)]
        NotInitialized,
        #[display("Failed to read config file")]
        ReadFailed(std::io::Error),
        #[display("Failed to parse config file")]
        ParseFailed(serde_yaml::Error),
    }

    // ...
    MainError := VCSError || WorkDirError || VCSOperationError || ConfigError || CheckError || RevisionError
}

and code around main() to print the chain of sources:

    if let Err(err) = main_inner() {
        // Print the error chain
        eprintln!("Error: {}", dbg!(&err));

        let mut source = std::error::Error::source(&err);
        while let Some(err) = source {
            eprintln!("Caused by: {}", err);
            source = std::error::Error::source(err);
        }

        std::process::exit(err.exit_code());
    }

But I get:

Starting check candidate=@ commit="105afdfd"
[src/main.rs:37:32] &err = ParseFailed(
    Error("job: unknown field `x`, expected one of `command`, `command-prefix`, `clone-mode`"
, line: 4, column: 3),
)
Error: Failed to parse config file

no chain in sight.

I use cargo expand and see:

#[allow(unused_qualifications)]
impl core::error::Error for ConfigError {
    fn source(&self) -> Option<&(dyn core::error::Error + 'static)> {
        match self {
            ConfigError::ReadFailed(source) => source.source(),
            ConfigError::ParseFailed(source) => source.source(),
            #[allow(unreachable_patterns)]
            _ => None,
        }
    }
}

which means the source for the ConfigError::Parse is not the source, but the source of the source, which is not what I was expecting.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions