Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't report errors getting readme when manifest is missing #2188

Merged
merged 2 commits into from
Aug 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions src/test/fakes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ pub(crate) struct FakeRelease<'a> {
readme: Option<&'a str>,
github_stats: Option<FakeGithubStats>,
doc_coverage: Option<DocCoverage>,
no_cargo_toml: bool,
}

pub(crate) struct FakeBuild {
Expand Down Expand Up @@ -96,6 +97,7 @@ impl<'a> FakeRelease<'a> {
github_stats: None,
doc_coverage: None,
archive_storage: false,
no_cargo_toml: false,
}
}

Expand Down Expand Up @@ -173,6 +175,11 @@ impl<'a> FakeRelease<'a> {
self
}

pub(crate) fn no_cargo_toml(mut self) -> Self {
self.no_cargo_toml = true;
self
}

pub(crate) fn default_target(mut self, target: &'a str) -> Self {
self = self.add_target(target);
self.default_target = Some(target);
Expand Down Expand Up @@ -354,10 +361,11 @@ impl<'a> FakeRelease<'a> {
let source_tmp = create_temp_dir();
store_files_into(&self.source_files, source_tmp.path())?;

if !self
.source_files
.iter()
.any(|&(path, _)| path == "Cargo.toml")
if !self.no_cargo_toml
&& !self
.source_files
.iter()
.any(|&(path, _)| path == "Cargo.toml")
{
let MetadataPackage { name, version, .. } = &package;
let content = format!(
Expand Down
24 changes: 22 additions & 2 deletions src/web/crate_details.rs
Original file line number Diff line number Diff line change
Expand Up @@ -241,12 +241,20 @@ impl CrateDetails {

#[fn_error_context::context("fetching readme for {} {}", self.name, self.version)]
fn fetch_readme(&self, storage: &Storage) -> anyhow::Result<Option<String>> {
let manifest = storage.fetch_source_file(
let manifest = match storage.fetch_source_file(
&self.name,
&self.version,
"Cargo.toml",
self.archive_storage,
)?;
) {
Ok(manifest) => manifest,
Err(err) if err.is::<PathNotFoundError>() => {
return Ok(None);
}
Err(err) => {
return Err(err);
}
};
let manifest = String::from_utf8(manifest.content)
.context("parsing Cargo.toml")?
.parse::<toml::Value>()
Expand Down Expand Up @@ -1188,6 +1196,14 @@ mod tests {
.source_file("Cargo.toml", br#"package.readme = "MEREAD""#)
.create()?;

env.fake_release()
.name("dummy")
.version("0.5.0")
.readme_only_database("database readme")
.source_file("README.md", b"storage readme")
.no_cargo_toml()
.create()?;

let check_readme = |path, content| {
let resp = env.frontend().get(path).send().unwrap();
let body = String::from_utf8(resp.bytes().unwrap().to_vec()).unwrap();
Expand All @@ -1199,6 +1215,10 @@ mod tests {
check_readme("/crate/dummy/0.3.0", "storage readme");
check_readme("/crate/dummy/0.4.0", "storage meread");

let details = CrateDetails::new(&mut *env.db().conn(), "dummy", "0.5.0", "0.5.0", None)
.unwrap()
.unwrap();
assert!(matches!(details.fetch_readme(&env.storage()), Ok(None)));
Ok(())
});
}
Expand Down
Loading