Skip to content

Commit b890973

Browse files
Do not panic if no commits loaded on status page
1 parent c99db6b commit b890973

File tree

2 files changed

+29
-25
lines changed

2 files changed

+29
-25
lines changed

site/src/api.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ pub mod status {
190190

191191
#[derive(Serialize, Debug)]
192192
pub struct Response {
193-
pub last_commit: Commit,
193+
pub last_commit: Option<Commit>,
194194
pub benchmarks: Vec<BenchmarkStatus>,
195195
pub missing: Vec<(Commit, MissingReason)>,
196196
pub current: Option<CurrentState>,

site/src/server.rs

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -249,30 +249,7 @@ fn prettify_log(log: &str) -> Option<String> {
249249

250250
pub async fn handle_status_page(data: Arc<InputData>) -> status::Response {
251251
let idx = data.index.load();
252-
let last_commit = idx.commits().last().unwrap().clone();
253-
254-
let mut benchmark_state = data
255-
.conn()
256-
.await
257-
.get_error(ArtifactId::from(last_commit.clone()).lookup(&idx).unwrap())
258-
.await
259-
.into_iter()
260-
.map(|(name, error)| {
261-
let msg = if let Some(error) = error {
262-
Some(prettify_log(&error).unwrap_or(error))
263-
} else {
264-
None
265-
};
266-
status::BenchmarkStatus {
267-
name,
268-
success: msg.is_none(),
269-
error: msg,
270-
}
271-
})
272-
.collect::<Vec<_>>();
273-
274-
benchmark_state.sort_by_key(|s| s.error.is_some());
275-
benchmark_state.reverse();
252+
let last_commit = idx.commits().last().cloned();
276253

277254
let missing = data.missing_commits().await;
278255
// FIXME: no current builds
@@ -298,6 +275,33 @@ pub async fn handle_status_page(data: Arc<InputData>) -> status::Response {
298275
None
299276
};
300277

278+
let errors = if let Some(last) = &last_commit {
279+
data.conn()
280+
.await
281+
.get_error(ArtifactId::from(last.clone()).lookup(&idx).unwrap())
282+
.await
283+
} else {
284+
Default::default()
285+
};
286+
let mut benchmark_state = errors
287+
.into_iter()
288+
.map(|(name, error)| {
289+
let msg = if let Some(error) = error {
290+
Some(prettify_log(&error).unwrap_or(error))
291+
} else {
292+
None
293+
};
294+
status::BenchmarkStatus {
295+
name,
296+
success: msg.is_none(),
297+
error: msg,
298+
}
299+
})
300+
.collect::<Vec<_>>();
301+
302+
benchmark_state.sort_by_key(|s| s.error.is_some());
303+
benchmark_state.reverse();
304+
301305
status::Response {
302306
last_commit,
303307
benchmarks: benchmark_state,

0 commit comments

Comments
 (0)