Make into_result_with_error_logging available for every MaybeCast<Output> type

This commit is contained in:
Leonard Steppy 2025-02-04 23:52:06 +01:00
parent 6c7e718748
commit 8315549838

View File

@ -202,15 +202,20 @@ impl<T> CommandResult<T, StartError> {
} }
} }
impl CommandResult<CommandOutput, ExecutionError<CommandOutput>> { impl<T> CommandResult<T, ExecutionError<T>> {
pub fn into_result_with_error_logging( pub fn into_result_with_error_logging(
self, self,
logger: &Logger, logger: &Logger,
) -> Result<CommandOutput, CommandError<ExecutionError<CommandOutput>>> { ) -> Result<T, CommandError<ExecutionError<T>>>
where
T: MaybeCast<CommandOutput>,
{
self.result.map_err(|error| { self.result.map_err(|error| {
if let ExecutionError::BadExitStatus(output) = &error { if let ExecutionError::BadExitStatus(t) = &error {
log!(logger, error, "{}", output.stdout.to_string_lossy()); if let Some(output) = t.maybe_cast() {
log!(logger, error, "{}", output.stderr.to_string_lossy()); log!(logger, error, "{}", output.stdout.to_string_lossy());
log!(logger, error, "{}", output.stderr.to_string_lossy());
}
} }
CommandError { CommandError {
command: self.command, command: self.command,