2024-10-03 12:47:35 +02:00
|
|
|
use std::{fmt::Display, process::ExitStatus};
|
2022-01-06 06:27:37 +02:00
|
|
|
|
2024-10-03 12:47:35 +02:00
|
|
|
use rust_i18n::t;
|
2019-12-11 23:05:38 +02:00
|
|
|
use thiserror::Error;
|
2018-12-11 16:43:26 +02:00
|
|
|
|
2025-06-25 19:46:49 +02:00
|
|
|
use crate::sudo::SudoKind;
|
|
|
|
|
|
2022-10-10 18:29:56 +00:00
|
|
|
#[derive(Error, Debug, PartialEq, Eq)]
|
2019-12-11 23:05:38 +02:00
|
|
|
pub enum TopgradeError {
|
2022-11-08 05:54:35 -05:00
|
|
|
ProcessFailed(String, ExitStatus),
|
2018-12-11 16:43:26 +02:00
|
|
|
|
2022-11-08 05:54:35 -05:00
|
|
|
ProcessFailedWithOutput(String, ExitStatus, String),
|
2020-06-25 08:37:29 +03:00
|
|
|
|
2018-12-11 16:43:26 +02:00
|
|
|
#[cfg(target_os = "linux")]
|
|
|
|
|
UnknownLinuxDistribution,
|
2022-01-06 06:27:37 +02:00
|
|
|
|
2023-07-24 02:27:13 +02:00
|
|
|
#[cfg(target_os = "linux")]
|
|
|
|
|
EmptyOSReleaseFile,
|
|
|
|
|
|
2022-01-06 06:27:37 +02:00
|
|
|
#[cfg(target_os = "linux")]
|
|
|
|
|
FailedGettingPackageManager,
|
2018-12-11 16:43:26 +02:00
|
|
|
}
|
|
|
|
|
|
2024-10-03 12:47:35 +02:00
|
|
|
impl Display for TopgradeError {
|
|
|
|
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
|
|
|
|
match self {
|
|
|
|
|
TopgradeError::ProcessFailed(process, exit_status) => {
|
|
|
|
|
write!(
|
|
|
|
|
f,
|
|
|
|
|
"{}",
|
|
|
|
|
t!(
|
2024-10-08 02:52:36 +02:00
|
|
|
"`{process}` failed: {exit_status}",
|
2024-10-03 12:47:35 +02:00
|
|
|
process = process,
|
|
|
|
|
exit_status = exit_status
|
|
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
TopgradeError::ProcessFailedWithOutput(process, exit_status, output) => {
|
|
|
|
|
write!(
|
|
|
|
|
f,
|
|
|
|
|
"{}",
|
|
|
|
|
t!(
|
2024-10-08 02:52:36 +02:00
|
|
|
"`{process}` failed: {exit_status} with {output}",
|
2024-10-03 12:47:35 +02:00
|
|
|
process = process,
|
|
|
|
|
exit_status = exit_status,
|
|
|
|
|
output = output
|
|
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
#[cfg(target_os = "linux")]
|
|
|
|
|
TopgradeError::UnknownLinuxDistribution => write!(f, "{}", t!("Unknown Linux Distribution")),
|
|
|
|
|
#[cfg(target_os = "linux")]
|
|
|
|
|
TopgradeError::EmptyOSReleaseFile => {
|
|
|
|
|
write!(f, "{}", t!("File \"/etc/os-release\" does not exist or is empty"))
|
|
|
|
|
}
|
|
|
|
|
#[cfg(target_os = "linux")]
|
|
|
|
|
TopgradeError::FailedGettingPackageManager => {
|
|
|
|
|
write!(f, "{}", t!("Failed getting the system package manager"))
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-12-11 23:05:38 +02:00
|
|
|
#[derive(Error, Debug)]
|
|
|
|
|
pub struct StepFailed;
|
2018-12-11 16:43:26 +02:00
|
|
|
|
2024-10-03 12:47:35 +02:00
|
|
|
impl Display for StepFailed {
|
|
|
|
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
|
|
|
|
write!(f, "{}", t!("A step failed"))
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-06-25 19:46:49 +02:00
|
|
|
#[derive(Error, Debug)]
|
|
|
|
|
pub struct UnsupportedSudo<'a> {
|
|
|
|
|
pub sudo_kind: SudoKind,
|
|
|
|
|
pub option: &'a str,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl Display for UnsupportedSudo<'_> {
|
|
|
|
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
|
|
|
|
write!(
|
|
|
|
|
f,
|
|
|
|
|
"{}",
|
|
|
|
|
t!(
|
|
|
|
|
"{sudo_kind} does not support the {option} option",
|
|
|
|
|
sudo_kind = self.sudo_kind,
|
|
|
|
|
option = self.option
|
|
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-09-26 15:41:38 +02:00
|
|
|
#[derive(Error, Debug)]
|
|
|
|
|
pub struct MissingSudo();
|
|
|
|
|
|
|
|
|
|
impl Display for MissingSudo {
|
|
|
|
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
|
|
|
|
write!(f, "{}", t!("Could not find sudo"))
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-02-27 06:41:55 +02:00
|
|
|
#[derive(Error, Debug)]
|
|
|
|
|
pub struct DryRun();
|
|
|
|
|
|
2024-10-03 12:47:35 +02:00
|
|
|
impl Display for DryRun {
|
|
|
|
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
|
|
|
|
write!(f, "{}", t!("Dry running"))
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-12-11 23:05:38 +02:00
|
|
|
#[derive(Error, Debug)]
|
2020-08-21 23:04:36 +03:00
|
|
|
pub struct SkipStep(pub String);
|
2018-12-11 16:43:26 +02:00
|
|
|
|
2024-10-03 12:47:35 +02:00
|
|
|
impl Display for SkipStep {
|
|
|
|
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
|
|
|
|
write!(f, "{}", self.0)
|
|
|
|
|
}
|
|
|
|
|
}
|