Repository: bottlerocket-os/bottlerocket
File: sources/api/certdog/src/main.rs (Rust)

Code before:
// Returning a Result from main makes it print a Debug representation of the error, but with Snafu
// we have nice Display representations of the error, so we wrap "main" (run) and print any error.
// https://github.com/shepmaster/snafu/issues/110
#[tokio::main]
async fn main() {
    if let Err(e) = run().await {
        error!("{}", e);
        process::exit(1);
    }
}

// =^..^=   =^..^=   =^..^=   =^..^=   =^..^=   =^..^=   =^..^=   =^..^=   =^..^=   =^..^=   =^..^=
mod error {
    use snafu::Snafu;
    use std::io;
    use std::path::PathBuf;

    #[derive(Debug, Snafu)]
    #[snafu(visibility(pub(super)))]
    pub(super) enum Error {
        #[snafu(display("Error sending {} to {}: {}", method, uri, source))]
        APIRequest {
            method: String,
            uri: String,
            #[snafu(source(from(apiclient::Error, Box::new)))]
            source: Box<apiclient::Error>,
        },

        #[snafu(display("Error reading data from configuration at {}: {}", config, source))]
        ConfigRead {
            config: String,
            #[snafu(source(from(std::io::Error, Box::new)))]
            source: Box<std::io::Error>,
        },

        #[snafu(display("Error deserializing pki from configuration at {}: {}", config, source))]
        ConfigDeserialization {
            config: String,
            #[snafu(source(from(toml::de::Error, Box::new)))]
            source: Box<toml::de::Error>,
        },

        #[snafu(display("Unable to decode base64 from certificate '{}': {}", name, source))]
        Base64Decode {
            name: String,
            source: base64::DecodeError,
        },

        #[snafu(display("Logger setup error: {}", source))]
        Logger { source: log::SetLoggerError },


Review comment (suggestion):
I can't comment on line 245: But the `APIRequest` error is no longer used. One quirk of Snafu's macros is that the compiler can't detect unused Error variants because Snafu is generating code in which they are used. Same with the `ResponseJson` Error variant.

Code after:
// Returning a Result from main makes it print a Debug representation of the error, but with Snafu
// we have nice Display representations of the error, so we wrap "main" (run) and print any error.
// https://github.com/shepmaster/snafu/issues/110
#[tokio::main]
async fn main() {
    if let Err(e) = run().await {
        error!("{}", e);
        process::exit(1);
    }
}

// =^..^=   =^..^=   =^..^=   =^..^=   =^..^=   =^..^=   =^..^=   =^..^=   =^..^=   =^..^=   =^..^=
mod error {
    use snafu::Snafu;
    use std::io;
    use std::path::PathBuf;

    #[derive(Debug, Snafu)]
    #[snafu(visibility(pub(super)))]
    pub(super) enum Error {
        #[snafu(display("Error reading data from configuration at {}: {}", config, source))]
        ConfigRead {
            config: String,
            #[snafu(source(from(std::io::Error, Box::new)))]
            source: Box<std::io::Error>,
        },

        #[snafu(display("Error deserializing pki from configuration at {}: {}", config, source))]
        ConfigDeserialization {
            config: String,
            #[snafu(source(from(toml::de::Error, Box::new)))]
            source: Box<toml::de::Error>,
        },

        #[snafu(display("Unable to decode base64 from certificate '{}': {}", name, source))]
        Base64Decode {
            name: String,
            source: base64::DecodeError,
        },

        #[snafu(display("Logger setup error: {}", source))]
        Logger { source: log::SetLoggerError },

        #[snafu(display("Invalid log level '{}'", log_level))]
        LogLevel {
            log_level: String,
            source: log::ParseLevelError,
        },

        #[snafu(display("Failed to parse PEM: {}", source))]
        ParsePEM {