GITv

Report a failed render as an error, accept ids in capitals, quiet MANIFEST

Browse files

- A page whose render panicked showed "Nothing here" with a 404 and the signed-out header; it is now a 500 that says the server went wrong, keeping the visitor's signed-in state. - The commit page refused ids in capitals although the lookup reads ids in any case; /commit?id=ABC123 now works. - Every backup MANIFEST had "stale" and "missing" lines, empty or not, so anything scanning for them saw false alarms; they appear only when a repository was held. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Author
Um9i vulgarmessiah@gmail.com
Date
22 Nov 2026, 22:32
Commit
d57b79807e6c
Parent
3e9c128

6 files changed +34−10

@@ -54,6 +54,19 @@ pub(crate) fn size(bytes: usize) -> String {
}
}
/// The page for a render that failed on the server's side: a bug, not a bad link.
pub(crate) fn view_failed(signed_in: bool) -> String {
templates::Notice {
title: "Something went wrong",
signed_in,
heading: "This page couldn’t be shown",
message: "Something went wrong on the server. Try again; if it keeps happening, the operator can see why in the log.",
code: None,
link: Some(("/", "Back to repositories")),
}
.to_string()
}
/// The page for anything that isn't there, or a malformed link.
pub(crate) fn view_missing(signed_in: bool) -> String {
templates::Notice {
@@ -26,7 +26,7 @@ use clap::{Parser, Subcommand};
use gitv_core::repos_root;
use gitv_web::render;
use crate::html::view_missing;
use crate::html::{view_failed, view_missing};
use crate::urls::{encode, lossy, parse_query};
use crate::views::{route, view_index};
use capacity::{Pool, Visitor};
@@ -213,11 +213,13 @@ async fn blocking(visitor: Visitor, f: impl FnOnce() -> View + Send + 'static) -
let view = f();
if started.elapsed() >= gitv_core::GIT_TIMEOUT { View::Busy } else { view }
};
let view = tokio::task::spawn_blocking(work).await.unwrap_or_else(|error| {
eprintln!("gitv-web: a page failed to render: {error}");
View::Missing(false)
});
view.response(visitor).await
match tokio::task::spawn_blocking(work).await {
Ok(view) => view.response(visitor).await,
Err(error) => {
eprintln!("gitv-web: a page failed to render: {error}");
html(StatusCode::INTERNAL_SERVER_ERROR, view_failed(visitor.signed_in))
}
}
}
/// A repository page: `/{owner}/{name}` (which redirects to its files) or
@@ -346,6 +348,9 @@ mod tests {
let response = blocking(visitor, || panic!("excess render was admitted")).await;
assert_eq!(response.status(), StatusCode::SERVICE_UNAVAILABLE);
drop(held);
// A render that fails is a server error, not a missing page.
let failed = blocking(visitor, || panic!("a render bug")).await;
assert_eq!(failed.status(), StatusCode::INTERNAL_SERVER_ERROR);
assert_eq!(blocking(visitor, || View::Html(String::new())).await.status(), StatusCode::OK);
}
}
@@ -113,7 +113,8 @@ pub(crate) fn parse_diff(text: &str) -> Vec<FileDiff> {
pub(crate) fn view_commit(repo: &Repo, q: &Q) -> Option<View> {
let id = param(q, "id")?;
if !(4..=64).contains(&id.len()) || !id.bytes().all(|b| b.is_ascii_digit() || (b'a'..=b'f').contains(&b)) {
// Any case: ids are hex, and the lookup reads them in lower case.
if !(4..=64).contains(&id.len()) || !id.bytes().all(|b| b.is_ascii_hexdigit()) {
return None;
}
// Looked up as an object only: a branch named like this id can't redirect the page.
@@ -275,6 +275,8 @@ fn huge_commits_still_show_what_changed() {
let s = server();
let page = s.get(&format!("/ada/site/commit?id={}", fixture().huge));
assert_eq!(page.status, 200, "the commit exists even when its diff is huge");
let upper = s.get(&format!("/ada/site/commit?id={}", fixture().huge[..12].to_uppercase()));
assert_eq!(upper.status, 200, "an id in capitals names the same commit");
let html = page.text();
assert!(html.contains("<h2 class=\"ctitle\">Add a huge file</h2>"));
assert!(html.contains("too large to show line by line"), "{html}");
@@ -107,7 +107,9 @@ fn snapshots_hold_everything_and_restore_whole() {
assert_eq!(fs::read_to_string(first.join("ssh-host-keys/ssh_host_ed25519_key")).unwrap(), "private\n");
assert!(first.join("ssh-host-keys/ssh_host_ed25519_key.pub").is_file());
assert!(!first.join("ssh-host-keys/sshd_config").exists(), "only the host keys are kept");
assert!(fs::read_to_string(first.join("MANIFEST")).unwrap().contains("repositories: 2"));
let manifest = fs::read_to_string(first.join("MANIFEST")).unwrap();
assert!(manifest.contains("repositories: 2"));
assert!(!manifest.contains("stale") && !manifest.contains("missing"), "a clean snapshot reports no problems");
// The next snapshot shares unchanged files with this one.
commit(&work, "Second");
@@ -151,8 +151,9 @@ rm -f "$base/fsck.err"
echo "snapshot: $stamp"
echo "host: $(hostname)"
echo "repositories: $count"
echo "stale (a push held them; copied from the previous snapshot): ${stale[*]}"
echo "missing (a push held them; never backed up): ${missing[*]}"
# Only when there is something to say, so anything scanning for these lines finds problems.
((${#stale[@]} == 0)) || echo "stale (a push held them; copied from the previous snapshot): ${stale[*]}"
((${#missing[@]} == 0)) || echo "missing (a push held them; never backed up): ${missing[*]}"
echo "previous: ${previous:+$(basename "$previous")}"
echo "$(git --version)"
} >"$snap/MANIFEST"