{"record":{"id":"49c4024189d7901b","repo":"GitoxideLabs/gitoxide","slug":"bug-need-tag","errorCode":null,"errorMessage":"BUG: need tag","messagePattern":"BUG: need tag","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"gix/src/object/mod.rs","lineNumber":227,"sourceCode":"    }\n\n    /// Obtain a tag token iterator from the data in this instance.\n    ///\n    /// # Panic\n    ///\n    /// - this object is not a tag\n    pub fn try_to_tag_ref_iter(&self) -> Option<gix_object::TagRefIter<'_>> {\n        gix_object::Data::new(&self.data, self.kind, self.id.kind()).try_into_tag_iter()\n    }\n\n    /// Obtain a tag object from the data in this instance.\n    ///\n    /// # Panic\n    ///\n    /// - this object is not a tag\n    /// - the tag could not be decoded\n    pub fn to_tag_ref(&self) -> gix_object::TagRef<'_> {\n        self.try_to_tag_ref().expect(\"BUG: need tag\")\n    }\n\n    /// Obtain a fully parsed tag object whose fields reference our data buffer.\n    pub fn try_to_tag_ref(&self) -> Result<gix_object::TagRef<'_>, conversion::Error> {\n        gix_object::Data::new(&self.data, self.kind, self.id.kind())\n            .decode()?\n            .into_tag()\n            .ok_or(conversion::Error::UnexpectedType {\n                expected: gix_object::Kind::Tag,\n                actual: self.kind,\n            })\n    }\n\n    /// Return the attached id of this object.\n    pub fn id(&self) -> Id<'repo> {\n        Id::from_id(self.id, self.repo)\n    }\n}","sourceCodeStart":209,"sourceCodeEnd":245,"githubUrl":"https://github.com/GitoxideLabs/gitoxide/blob/e73179060badf27222d790981fac3f84c1830a7e/gix/src/object/mod.rs#L209-L245","documentation":"Object::to_tag_ref() wraps try_to_tag_ref() and expects success. It panics when the object is not a tag or the tag object fails to decode, as stated in its # Panic docs. It is the non-fallible convenience for callers who already know the kind.","triggerScenarios":"Calling to_tag_ref() on an object of kind Commit, Tree, or Blob; calling it on a malformed tag object whose decode fails.","commonSituations":"Resolving refs that point at commits rather than annotated tags; user-supplied object ids; repositories with corrupt or partially-written tag objects.","solutions":["Check obj.kind == gix_object::Kind::Tag before converting.","Use try_to_tag_ref() and handle the Result gracefully.","Peel/validate via peel_to_kind(gix_object::Kind::Tag)? first."],"exampleFix":"// before\nlet tag = obj.to_tag_ref(); // panics if not a tag\n// after\nlet tag = obj.try_to_tag_ref()\n    .ok_or_else(|| anyhow::anyhow!(\"expected tag, got {:?}\", obj.kind))?;","handlingStrategy":"type-guard","validationCode":"if obj.kind == gix_object::Kind::Tag {\n    let tag = obj.to_tag_ref();\n}","typeGuard":"fn try_tag(obj: &gix::Object) -> Option<gix_object::TagRef<'_>> { obj.try_to_tag_ref().ok() }","tryCatchPattern":null,"preventionTips":["Prefer try_to_tag_ref() to convert panics into Results.","Check Object::kind == Tag before conversion.","Peel or branch on kind for user-supplied object ids."],"tags":["rust","panic","object-conversion","tag"],"backgroundTag":"incompatible-source-type","analyzedSha":"e73179060badf27222d790981fac3f84c1830a7e","analyzedAt":"2026-09-08T11:26:50.865Z","contentChangedAt":"2026-09-08T11:26:50.865Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}