{"record":{"id":"b797556ffcfc1a6c","repo":"gitbutlerapp/gitbutler","slug":"bug-value-must-be-valid-ref-name","errorCode":null,"errorMessage":"BUG: value must be valid ref name","messagePattern":"BUG: value must be valid ref name","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/gitbutler-branch/src/branch.rs","lineNumber":68,"sourceCode":"        self.0.as_ref().as_bstr()\n    }\n}\n\n/// Facilitate obtaining this type from the UI.\nimpl TryFrom<String> for BranchIdentity {\n    type Error = gix::refs::name::Error;\n\n    fn try_from(value: String) -> std::result::Result<Self, Self::Error> {\n        gix::refs::PartialName::try_from(value).map(BranchIdentity)\n    }\n}\n\n/// Used in testing, and **panics** if the value isn't a valid partial ref name\nimpl From<&str> for BranchIdentity {\n    fn from(value: &str) -> Self {\n        gix::refs::PartialName::try_from(value)\n            .map(BranchIdentity)\n            .expect(\"BUG: value must be valid ref name\")\n    }\n}\n\n/// Used in for short-name conversions\nimpl TryFrom<&BStr> for BranchIdentity {\n    type Error = gix::refs::name::Error;\n\n    fn try_from(value: &BStr) -> std::result::Result<Self, Self::Error> {\n        gix::refs::PartialName::try_from(value.to_owned()).map(BranchIdentity)\n    }\n}\n\nimpl std::fmt::Display for BranchIdentity {\n    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {\n        write!(f, \"{}\", self.0.as_ref().as_bstr().to_str_lossy())\n    }\n}\n","sourceCodeStart":50,"sourceCodeEnd":86,"githubUrl":"https://github.com/gitbutlerapp/gitbutler/blob/58e5313667b857ef39a730e380af31816a7b1768/crates/gitbutler-branch/src/branch.rs#L50-L86","documentation":"BranchIdentity implements From<&str> by parsing the string as a gix::refs::PartialName and expects success. The impl is documented as test-only convenience: it panics if the value is not a valid partial ref name. Production code should use TryFrom<&BStr> which returns gix::refs::name::Error instead.","triggerScenarios":"Constructing a BranchIdentity from a &str containing characters or formatting invalid for a git partial ref name (e.g. spaces, leading dots, '..' sequences, empty string).","commonSituations":"Tests using convenient string literals (intended use), or accidental production use of the From impl with user-supplied branch names that aren't valid ref names.","solutions":["Validate the branch name before conversion, or use TryFrom<&BStr> for BranchIdentity and handle the error","Restrict From<&str> usage to tests; in application code accept BranchIdentity only via fallible conversions","Sanitize user input into a valid git ref name (e.g. via gix validate) before building a BranchIdentity"],"exampleFix":"// before\nlet identity = BranchIdentity::from(user_branch_name); // panics on invalid name\n// after\nlet identity = BranchIdentity::try_from(gix::bstr::ByteSlice::as_bstr(user_branch_name.as_bytes()))\n    .context(\"invalid branch name\")?;","handlingStrategy":"validation","validationCode":"// Rust: validate before conversion\nfn is_valid_partial_name(value: &str) -> bool {\n    gix::refs::PartialName::try_from(value).is_ok()\n}","typeGuard":"fn try_branch_identity(value: &str) -> Option<BranchIdentity> {\n    gix::refs::PartialName::try_from(value).ok().map(BranchIdentity)\n}","tryCatchPattern":"// Panics cannot be caught idiomatically in Rust; prefer the fallible API:\nlet identity = BranchIdentity::try_from(gix::bstr::BStr::new(value))\n    .map_err(|e| anyhow::anyhow!(\"invalid branch name {value:?}: {e}\"))?;","preventionTips":["Never use From<&str> for BranchIdentity outside tests","Validate user-supplied branch names with gix ref-name validation before conversion","Prefer TryFrom<&BStr> at all application boundaries"],"tags":["rust","git","refname","panic","testing"],"backgroundTag":"invalid-argument-value","analyzedSha":"58e5313667b857ef39a730e380af31816a7b1768","analyzedAt":"2026-09-18T06:50:32.052Z","contentChangedAt":"2026-09-18T06:50:32.052Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}