feat: better error message on wrong os-release file (#511)
* enhancement: better error message when os-release parsing fails
This commit is contained in:
@@ -14,6 +14,10 @@ pub enum TopgradeError {
|
||||
#[cfg(target_os = "linux")]
|
||||
UnknownLinuxDistribution,
|
||||
|
||||
#[error("File \"/etc/os-release\" does not exist or is empty")]
|
||||
#[cfg(target_os = "linux")]
|
||||
EmptyOSReleaseFile,
|
||||
|
||||
#[error("Failed getting the system package manager")]
|
||||
#[cfg(target_os = "linux")]
|
||||
FailedGettingPackageManager,
|
||||
|
||||
@@ -114,10 +114,14 @@ impl Distribution {
|
||||
if PathBuf::from(OS_RELEASE_PATH).exists() {
|
||||
let os_release = Ini::load_from_file(OS_RELEASE_PATH)?;
|
||||
|
||||
if os_release.general_section().is_empty() {
|
||||
return Err(TopgradeError::EmptyOSReleaseFile.into());
|
||||
}
|
||||
|
||||
return Self::parse_os_release(&os_release);
|
||||
}
|
||||
|
||||
Err(TopgradeError::UnknownLinuxDistribution.into())
|
||||
Err(TopgradeError::EmptyOSReleaseFile.into())
|
||||
}
|
||||
|
||||
pub fn upgrade(self, ctx: &ExecutionContext) -> Result<()> {
|
||||
|
||||
Reference in New Issue
Block a user