gitbutlerapp/gitbutler · info
statically known
Error message
statically known
What it means
workspace_data_of_default_workspace_branch() converts the compile-time constant WORKSPACE_REF_NAME ("refs/heads/gitbutler/workspace", but-core/src/lib.rs:128) into a validated gix ref name via try_into().expect("statically known"). The conversion into a gix::refs::FullName/FullNameRef only fails for syntactically invalid ref names, and the constant is valid, so this expect is an unreachable invariant rather than a runtime condition. A panic here means someone edited WORKSPACE_REF_NAME to a string git rejects.
Source
Thrown at crates/but-workspace/src/ref_info.rs:902
if !is_workspace_ref_name(name) {
return Ok(None);
}
let md = meta.workspace(name)?;
Ok(if md.is_default() {
None
} else {
Some((*md).clone())
})
}
/// Like [`workspace_data_of_workspace_branch()`], but it will try the name of the default GitButler workspace branch.
pub(crate) fn workspace_data_of_default_workspace_branch(
meta: &impl but_core::RefMetadata,
) -> anyhow::Result<Option<but_core::ref_metadata::Workspace>> {
workspace_data_of_workspace_branch(
meta,
WORKSPACE_REF_NAME.try_into().expect("statically known"),
)
}
#[cfg(test)]
mod review_association_tests {
use std::collections::HashMap;
use super::{apply_review_to_metadata, forge_review_for_branch};
use but_core::ref_metadata::Branch;
fn branch_with_review(review: Option<usize>) -> Branch {
let mut branch = Branch::default();
branch.review.pull_request = review;
branch
}
#[test]
fn managed_segment_gets_the_matched_review() {View on GitHub (pinned to caf1f223d3)
Solutions
- Keep WORKSPACE_REF_NAME a valid fully-qualified ref (refs/heads/gitbutler/workspace); if you changed it, revert or fix the value
- Add a unit test asserting gix::refs::FullName::try_from(WORKSPACE_REF_NAME).is_ok() so an invalid constant fails CI instead of panicking at runtime
- If the ref name must come from configuration, use the fallible form like but-api does: meta.workspace(WORKSPACE_REF_NAME.try_into()?)?
Example fix
// before
WORKSPACE_REF_NAME.try_into().expect("statically known")
// after - validate the constant once in a test instead of asserting on every call
#[test]
fn workspace_ref_name_is_valid() {
gix::refs::FullName::try_from(but_core::WORKSPACE_REF_NAME).unwrap();
} Defensive patterns
Strategy: validation
Validate before calling
// Verify the constant still parses before relying on the invariant (run in CI)
#[test]
fn workspace_ref_name_is_valid() {
assert!(
gix::refs::FullName::try_from(but_core::WORKSPACE_REF_NAME).is_ok(),
"WORKSPACE_REF_NAME must remain a valid fully-qualified ref"
);
} Type guard
fn is_valid_workspace_ref(name: &str) -> bool {
gix::refs::FullName::try_from(name).is_ok()
} Prevention
- Never apply this expect pattern to runtime-supplied ref names - use .try_into()? instead
- Keep a unit test that parses every ref-name constant used with expect
- Prefer the fallible APIs already used elsewhere, e.g. meta.workspace(WORKSPACE_REF_NAME.try_into()?)?
When it happens
Trigger: Calling workspace_data_of_default_workspace_branch(&metadata) on any but-workspace RefInfo computation. The panic fires only if WORKSPACE_REF_NAME is changed to a value gix::refs::FullName::try_from rejects: empty string, spaces, backslashes, control characters, or a non-fully-qualified name like "workspace".
Common situations: Refactors renaming the workspace ref constant, or copying this expect pattern onto a new, runtime-supplied ref name that is not statically guaranteed. No CLI/API input can trigger it as shipped.
Related errors
- prefiltered
- a committed transaction always materializes a workspace
- known statically
- anchor is always present in the order at this point
- symbols must always be initialized
AI-assisted analysis of gitbutlerapp/gitbutler@caf1f223d3 (2026-08-20).
Data as JSON: /api/errors/4bde4acdbdae327a.
Report an issue: GitHub.