{"record":{"id":"4dc5bfd3589fd786","repo":"GitoxideLabs/gitoxide","slug":"bug-this-object-must-be-a-tag","errorCode":null,"errorMessage":"BUG: this object must be a tag","messagePattern":"BUG: this object must be a tag","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"gix/src/object/mod.rs","lineNumber":208,"sourceCode":"        gix_object::Data::new(&self.data, self.kind, self.id.kind())\n            .try_into_commit_iter()\n            .expect(\"BUG: This object must be a commit\")\n    }\n\n    /// Obtain a commit token iterator from the data in this instance, if it is a commit.\n    pub fn try_to_commit_ref_iter(&self) -> Option<gix_object::CommitRefIter<'_>> {\n        gix_object::Data::new(&self.data, self.kind, self.id.kind()).try_into_commit_iter()\n    }\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 to_tag_ref_iter(&self) -> gix_object::TagRefIter<'_> {\n        gix_object::Data::new(&self.data, self.kind, self.id.kind())\n            .try_into_tag_iter()\n            .expect(\"BUG: this object must be a tag\")\n    }\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<'_> {","sourceCodeStart":190,"sourceCodeEnd":226,"githubUrl":"https://github.com/GitoxideLabs/gitoxide/blob/e73179060badf27222d790981fac3f84c1830a7e/gix/src/object/mod.rs#L190-L226","documentation":"Object::to_tag_ref_iter() converts the object into a TagRefIter, valid only for objects of kind Tag. The expect panics otherwise, matching the documented # Panic condition. Internal callers (peel_to_kind, peel_tags_to_end) rely on it after filtering to tag objects.","triggerScenarios":"Calling to_tag_ref_iter() on an object of kind Commit, Tree, or Blob; calling peel_to_kind(Tag)/peel_tags_to_end logic on unexpected object kinds in custom code paths.","commonSituations":"Walking objects without checking kind; assuming a lightweight ref points to an annotated tag object; deserializing arbitrary object ids from user input.","solutions":["Verify obj.kind == gix_object::Kind::Tag before calling to_tag_ref_iter().","Use try_to_tag_ref_iter() which returns Option and handle the None case.","Peel or branch by kind before invoking tag-specific iteration."],"exampleFix":"// before\nlet tag = obj.to_tag_ref_iter(); // panics if not a tag\n// after\nif obj.kind == gix_object::Kind::Tag {\n    let tag = obj.to_tag_ref_iter();\n    // ...\n}","handlingStrategy":"type-guard","validationCode":"if obj.kind == gix_object::Kind::Tag {\n    let tag = obj.to_tag_ref_iter();\n}","typeGuard":"fn as_tag_iter(obj: &gix::Object) -> Option<gix_object::TagRefIter<'_>> { obj.try_to_tag_ref_iter() }","tryCatchPattern":null,"preventionTips":["Use try_to_tag_ref_iter() when the kind is uncertain.","Remember lightweight tags point at commits, not tag objects - check kind.","Branch on Object::kind before tag-specific parsing."],"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-16T04:17:20.429Z"}