Repository: microsoft/onefuzz
File: src/agent/onefuzz-task/src/tasks/report/dotnet/common.rs (Rust)

Code before:
        if let Some(captures) = INNER_EXCEPTION.captures(line) {
            if let Some(c) = captures.get(1) {
                inner_exception = Some(c.as_str().to_owned());
                continue;
            }
        }

        if let Some(captures) = STACK_FRAME.captures(line) {
            if let Some(c) = captures.get(3) {
                let frame = c.as_str().to_owned();
                call_stack.push(frame);
                continue;
            }
        }

        if let Some(captures) = HRESULT.captures(line) {
            if let Some(c) = captures.get(1) {
                hresult = Some(c.as_str().to_owned());
                continue;
            }
        }
    }

    let exception =
        exception.ok_or_else(|| format_err!("missing exception type, output was:\n{}", text))?;
    let message = message.ok_or_else(|| format_err!("missing exception message"))?;

    let inner_exception = inner_exception.ok_or_else(|| format_err!("missing inner exception"))?;
    let inner_exception = if inner_exception == "<none>" {
        None
    } else {
        Some(inner_exception)
    };

    let hresult = hresult.ok_or_else(|| format_err!("missing exception hresult"))?;

    if call_stack.is_empty() {
        bail!("missing call_stack");
    }

    Ok(DotnetExceptionInfo {
        exception,
        message,
        inner_exception,
        call_stack,
        hresult,
    })
}

// https://docs.microsoft.com/en-us/dotnet/core/diagnostics/dotnet-dump#analyze-sos-commands
const SOS_EXIT: &str = "exit";

Review comment (suggestion):
really we should collect up all the missing info and report it all at once (is there a `Validation` type?)

Code after:

        if let Some(captures) = INNER_EXCEPTION.captures(line) {
            if let Some(c) = captures.get(1) {
                inner_exception = Some(c.as_str().to_owned());
                continue;
            }
        }

        if let Some(captures) = STACK_FRAME.captures(line) {
            if let Some(c) = captures.get(3) {
                let frame = c.as_str().to_owned();
                call_stack.push(frame);
                continue;
            }
        }

        if let Some(captures) = HRESULT.captures(line) {
            if let Some(c) = captures.get(1) {
                hresult = Some(c.as_str().to_owned());
                continue;
            }
        }
    }

    let exception =
        exception.ok_or_else(|| format_err!("missing exception type, output was:\n{}", text))?;
    let message = message.ok_or_else(|| format_err!("missing exception message"))?;

    let inner_exception = inner_exception.ok_or_else(|| format_err!("missing inner exception"))?;
    let inner_exception = if inner_exception == "<none>" {
        None
    } else {
        Some(inner_exception)
    };

    let hresult = hresult.ok_or_else(|| format_err!("missing exception hresult"))?;

    if call_stack.is_empty() {
        bail!("missing call_stack");
    }

    Ok(DotnetExceptionInfo {
        exception,
        message,
        inner_exception,
        call_stack,
        hresult,
    })
}

// https://docs.microsoft.com/en-us/dotnet/core/diagnostics/dotnet-dump#analyze-sos-commands