Add a dedicated error for missing RECORD files (#762)

Related to: https://github.com/astral-sh/puffin/issues/716
This commit is contained in:
Charlie Marsh 2024-01-03 20:28:50 -04:00 committed by GitHub
parent 2d1d6ac0dd
commit 286145bc7f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 74 additions and 2 deletions

View file

@ -80,6 +80,8 @@ pub enum Error {
DirectUrlJson(#[from] serde_json::Error),
#[error("No .dist-info directory found")]
MissingDistInfo,
#[error("Cannot uninstall package; RECORD file not found at: {0}")]
MissingRecord(PathBuf),
#[error("Multiple .dist-info directories found: {0}")]
MultipleDistInfo(String),
#[error("Invalid wheel size")]

View file

@ -2,7 +2,6 @@ use std::collections::BTreeSet;
use std::path::{Component, Path, PathBuf};
use fs_err as fs;
use fs_err::File;
use tracing::debug;
use crate::{read_record_file, Error};
@ -16,7 +15,14 @@ pub fn uninstall_wheel(dist_info: &Path) -> Result<Uninstall, Error> {
};
// Read the RECORD file.
let mut record_file = File::open(dist_info.join("RECORD"))?;
let record_path = dist_info.join("RECORD");
let mut record_file = match fs::File::open(&record_path) {
Ok(record_file) => record_file,
Err(err) if err.kind() == std::io::ErrorKind::NotFound => {
return Err(Error::MissingRecord(record_path));
}
Err(err) => return Err(err.into()),
};
let record = read_record_file(&mut record_file)?;
let mut file_count = 0usize;