Skip to content

Commit

Permalink
fix regression in source views when releases.files is NULL
Browse files Browse the repository at this point in the history
This fixes https://sentry.io/organizations/rust-lang/issues/3796296974/
where we previouly converted any error into `None`, which was converted
into `Nope::ResourceNotFound` for the whole source page.

This fix re-introduces this behavior and makes it more explicit
  • Loading branch information
syphar committed Dec 12, 2022
1 parent 013508c commit 9f1a0c2
Showing 1 changed file with 35 additions and 1 deletion.
36 changes: 35 additions & 1 deletion src/web/source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,11 @@ impl FileList {
None => return Ok(None),
};

let files: Value = row.try_get(5)?;
let files = if let Some(files) = row.try_get::<_, Option<Value>>(5)? {
files
} else {
return Ok(None);
};

let mut file_list = Vec::new();
if let Some(files) = files.as_array() {
Expand Down Expand Up @@ -306,6 +310,7 @@ mod tests {
use crate::test::*;
use crate::web::cache::CachePolicy;
use kuchiki::traits::TendrilSink;
use reqwest::StatusCode;
use test_case::test_case;

fn get_file_list_links(body: &str) -> Vec<String> {
Expand Down Expand Up @@ -368,6 +373,35 @@ mod tests {
});
}

#[test_case(true)]
#[test_case(false)]
fn empty_file_list_dont_break_the_view(archive_storage: bool) {
wrapper(|env| {
let release_id = env
.fake_release()
.archive_storage(archive_storage)
.name("fake")
.version("0.1.0")
.source_file("README.md", b"hello")
.create()?;

let path = "/crate/fake/0.1.0/source/README.md";
let web = env.frontend();
assert_success(path, web)?;

env.db().conn().execute(
"UPDATE releases
SET files = NULL
WHERE id = $1",
&[&release_id],
)?;

assert_eq!(web.get(path).send()?.status(), StatusCode::NOT_FOUND);

Ok(())
});
}

#[test]
fn latest_contains_links_to_latest() {
wrapper(|env| {
Expand Down

0 comments on commit 9f1a0c2

Please sign in to comment.