Skip to content

Commit

Permalink
fix: Don't panic on nested group (#4037)
Browse files Browse the repository at this point in the history
  • Loading branch information
max-sixty authored Jan 11, 2024
1 parent 29dbf8b commit a110d9c
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 1 deletion.
4 changes: 3 additions & 1 deletion prqlc/prql-compiler/src/semantic/lowering.rs
Original file line number Diff line number Diff line change
Expand Up @@ -946,7 +946,9 @@ impl Lowerer {
panic!("cannot find cid by id={id} and name={name:?}");
}
}
None => panic!("cannot find cid by id={id}"),
None => {
return Err(Error::new(Reason::Bug { issue: Some(3870) }))?;
}
};

Ok(cid)
Expand Down
20 changes: 20 additions & 0 deletions prqlc/prql-compiler/tests/integration/bad_error_messages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,3 +175,23 @@ fn test_relation_literal_contains_literals() {
───╯
"###)
}

#[test]
fn nested_groups() {
// Nested `group` gives a very abstract & internally-focused error message
assert_display_snapshot!(compile(r###"
from inv=invoices
join item=invoice_items (==invoice_id)
group { inv.billing_city } (
group { item.name } (
aggregate {
ct1 = count inv.name,
}
)
)
"###).unwrap_err(), @r###"
Error: internal compiler error; tracked at https://github.com/PRQL/prql/issues/3870
"###);
}
11 changes: 11 additions & 0 deletions prqlc/prqlc-ast/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ pub enum Reason {
name: String,
namespace: String,
},
Bug {
issue: Option<i32>,
},
}

impl Error {
Expand Down Expand Up @@ -76,6 +79,14 @@ impl std::fmt::Display for Reason {
}
Reason::Unexpected { found } => write!(f, "unexpected {found}"),
Reason::NotFound { name, namespace } => write!(f, "{namespace} `{name}` not found"),
Reason::Bug { issue } => match issue {
Some(issue) => write!(
f,
"internal compiler error; tracked at https://github.com/PRQL/prql/issues/{}",
issue
),
None => write!(f, "internal compiler error"),
},
}
}
}
Expand Down

0 comments on commit a110d9c

Please sign in to comment.