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

Code before:

        debug!("Running generator: '{}'", &generator);

        // Split on space, assume the first item is the command
        // and the rest are args.
        let mut command_strings = generator.split_whitespace();
        let command = command_strings.next().context(error::InvalidCommandSnafu {
            command: generator.as_str(),
        })?;

        let result = process::Command::new(command)
            .envs(&proxy_envs)
            .args(command_strings)
            .output()
            .context(error::CommandFailureSnafu {
                program: generator.as_str(),
            })?;

        // Match on the generator's exit code. This code lays the foundation
        // for handling alternative exit codes from generators.
        match result.status.code() {
            Some(0) => {}
            Some(1) => {
                return error::FailedSettingGeneratorSnafu {
                    program: generator.as_str(),
                    code: 1.to_string(),
                    stderr: String::from_utf8_lossy(&result.stderr),
                }
                .fail()
            }
            Some(2) => {
                warn!(
                    "'{}' returned 2, not setting '{}', continuing with other generators",
                    command, generator
                );
                continue;
            }
            Some(x) => {
                return error::UnexpectedReturnCodeSnafu {
                    program: generator.as_str(),
                    code: x.to_string(),
                    stderr: String::from_utf8_lossy(&result.stderr),
                }
                .fail()
            }
            // A process will return None if terminated by a signal, regard this as
            // a failure since we could have incomplete data
            None => {
                return error::FailedSettingGeneratorSnafu {
                    program: generator.as_str(),
                    code: "signal",

Review comment (suggestion):
Nit: perhaps the log could be a little bit more verbose so we know exactly what we're looking at in the logs. It could get a little confusing in the context of the whole journal.
```
info!("Setting generator command '{}' stderr: {}", command, line);
```

Code after:

        debug!("Running generator: '{}'", &generator);

        // Split on space, assume the first item is the command
        // and the rest are args.
        let mut command_strings = generator.split_whitespace();
        let command = command_strings.next().context(error::InvalidCommandSnafu {
            command: generator.as_str(),
        })?;

        let result = process::Command::new(command)
            .envs(&proxy_envs)
            .args(command_strings)
            .output()
            .context(error::CommandFailureSnafu {
                program: generator.as_str(),
            })?;

        // Match on the generator's exit code. This code lays the foundation
        // for handling alternative exit codes from generators.
        match result.status.code() {
            Some(0) => {
                if !result.stderr.is_empty() {
                    let cmd_stderr = String::from_utf8_lossy(&result.stderr);
                    for line in cmd_stderr.lines() {
                        info!("Setting generator command '{}' stderr: {}", command, line);
                    }
                }
            }
            Some(1) => {
                return error::FailedSettingGeneratorSnafu {
                    program: generator.as_str(),
                    code: 1.to_string(),
                    stderr: String::from_utf8_lossy(&result.stderr),
                }
                .fail()
            }
            Some(2) => {
                warn!(
                    "'{}' returned 2, not setting '{}', continuing with other generators",
                    command, generator
                );
                continue;
            }
            Some(x) => {
                return error::UnexpectedReturnCodeSnafu {
                    program: generator.as_str(),
                    code: x.to_string(),
                    stderr: String::from_utf8_lossy(&result.stderr),
                }
                .fail()