Skip to content

Commit

Permalink
fix panic when searching an the root span (vercel/turborepo#7936)
Browse files Browse the repository at this point in the history
### Description

<!--
  ✍️ Write a short summary of your work.
  If necessary, include relevant screenshots.
-->

### Testing Instructions

<!--
  Give a quick description of steps to test your changes.
-->


Closes PACK-2934
  • Loading branch information
sokra authored Apr 15, 2024
1 parent 7336ae0 commit b0630d6
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 30 deletions.
64 changes: 35 additions & 29 deletions crates/turbopack-trace-server/src/span_ref.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ impl<'a> SpanRef<'a> {
self.span.is_complete
}

pub fn is_root(&self) -> bool {
self.index == 0
}

pub fn nice_name(&self) -> (&'a str, &'a str) {
let (category, title) = self.names().nice_name.get_or_init(|| {
if let Some(name) = self
Expand Down Expand Up @@ -357,35 +361,37 @@ impl<'a> SpanRef<'a> {
let mut queue = VecDeque::with_capacity(8);
queue.push_back(*self);
while let Some(span) = queue.pop_front() {
let (cat, name) = span.nice_name();
if !cat.is_empty() {
index
.raw_entry_mut()
.from_key(cat)
.and_modify(|_, v| v.push(span.index()))
.or_insert_with(|| (cat.to_string(), vec![span.index()]));
}
if !name.is_empty() {
index
.raw_entry_mut()
.from_key(name)
.and_modify(|_, v| v.push(span.index()))
.or_insert_with(|| (name.to_string(), vec![span.index()]));
}
for (_, value) in span.span.args.iter() {
index
.raw_entry_mut()
.from_key(value)
.and_modify(|_, v| v.push(span.index()))
.or_insert_with(|| (value.to_string(), vec![span.index()]));
}
if !span.is_complete() {
let name = "incomplete";
index
.raw_entry_mut()
.from_key(name)
.and_modify(|_, v| v.push(span.index()))
.or_insert_with(|| (name.to_string(), vec![span.index()]));
if !span.is_root() {
let (cat, name) = span.nice_name();
if !cat.is_empty() {
index
.raw_entry_mut()
.from_key(cat)
.and_modify(|_, v| v.push(span.index()))
.or_insert_with(|| (cat.to_string(), vec![span.index()]));
}
if !name.is_empty() {
index
.raw_entry_mut()
.from_key(name)
.and_modify(|_, v| v.push(span.index()))
.or_insert_with(|| (name.to_string(), vec![span.index()]));
}
for (_, value) in span.span.args.iter() {
index
.raw_entry_mut()
.from_key(value)
.and_modify(|_, v| v.push(span.index()))
.or_insert_with(|| (value.to_string(), vec![span.index()]));
}
if !span.is_complete() {
let name = "incomplete";
index
.raw_entry_mut()
.from_key(name)
.and_modify(|_, v| v.push(span.index()))
.or_insert_with(|| (name.to_string(), vec![span.index()]));
}
}
for child in span.children() {
queue.push_back(child);
Expand Down
4 changes: 3 additions & 1 deletion crates/turbopack-trace-server/src/viewer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,9 @@ impl Viewer {
}
}
}
if !has_results {
if has_results {
highlighted_spans.insert(span.id());
} else {
children.last_mut().unwrap().item.filtered = true;
}
}
Expand Down

0 comments on commit b0630d6

Please sign in to comment.