Skip to content

Commit f0c03d1

Browse files
authored
Turn a possible panic into an error message that will help to debug it. (#9886)
* Turn a possible panic into an error message that will help to debug it. * Make `d o t` available to everyone to ease debugging. The disadvantage is that we then launch`dot`, assuming it is the program we know to create an SVG, and we write a file to disk. It should, however, be hard to trigger by accident, and I'd assume calling this won't destroy anything.
1 parent 69ded82 commit f0c03d1

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

crates/but-graph/src/init/post.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use crate::init::walk::{RefsById, disambiguate_refs_by_branch_metadata};
44
use crate::init::{PetGraph, branch_segment_from_name_and_meta, remotes};
55
use crate::projection::workspace;
66
use crate::{Commit, CommitFlags, CommitIndex, Edge, Graph, SegmentIndex, SegmentMetadata};
7-
use anyhow::bail;
7+
use anyhow::{Context as _, bail};
88
use but_core::{RefMetadata, ref_metadata};
99
use gix::prelude::ObjectIdExt;
1010
use gix::reference::Category;
@@ -176,7 +176,17 @@ impl Graph {
176176
meta: &OverlayMetadata<'_, T>,
177177
) -> anyhow::Result<SegmentIndex> {
178178
let s = &mut self[sidx];
179-
let tip_of_new_segment = s.commits[cidx_for_new_segment].id;
179+
let tip_of_new_segment = s
180+
.commits
181+
.get(cidx_for_new_segment)
182+
.with_context(|| {
183+
format!(
184+
"Segment {sidx:?} \
185+
has only {} commit(s), cannot split at {cidx_for_new_segment}",
186+
s.commits.len()
187+
)
188+
})?
189+
.id;
180190
let new_segment_commits = s.commits.drain(cidx_for_new_segment..).collect();
181191
let last_cidx_in_top_segment = s.last_commit_index();
182192
let edges_to_reconnect: Vec<_> = self

crates/gitbutler-tauri/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ fn main() {
332332
// Debug-only - not for production!
333333
#[cfg(debug_assertions)]
334334
env::env_vars,
335-
#[cfg(all(debug_assertions, unix))]
335+
#[cfg(unix)]
336336
workspace::show_graph_svg,
337337
claude::claude_send_message,
338338
claude::claude_get_messages

0 commit comments

Comments
 (0)