{"record":{"id":"2841c4264b7778e6","repo":"GitoxideLabs/gitoxide","slug":"bug-this-object-must-be-a-commit","errorCode":null,"errorMessage":"BUG: This object must be a commit","messagePattern":"BUG: This object must be a commit","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"gix/src/object/mod.rs","lineNumber":192,"sourceCode":"    pub fn try_to_commit_ref(&self) -> Result<gix_object::CommitRef<'_>, conversion::Error> {\n        gix_object::Data::new(&self.data, self.kind, self.id.kind())\n            .decode()?\n            .into_commit()\n            .ok_or(conversion::Error::UnexpectedType {\n                expected: gix_object::Kind::Commit,\n                actual: self.kind,\n            })\n    }\n\n    /// Obtain an iterator over commit tokens like in [`to_commit_iter()`][Object::try_to_commit_ref_iter()].\n    ///\n    /// # Panic\n    ///\n    /// - this object is not a commit\n    pub fn to_commit_ref_iter(&self) -> gix_object::CommitRefIter<'_> {\n        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","sourceCodeStart":174,"sourceCodeEnd":210,"githubUrl":"https://github.com/GitoxideLabs/gitoxide/blob/e73179060badf27222d790981fac3f84c1830a7e/gix/src/object/mod.rs#L174-L210","documentation":"Object::to_commit_ref_iter() converts the object data into a CommitRefIter, which only works if the object kind is Commit. The expect panics for any other object kind, as documented in the method's # Panic section.","triggerScenarios":"Calling to_commit_ref_iter() on an object of kind Blob, Tree, or Tag.","commonSituations":"Resolving a ref or rev-spec that points to an annotated tag or tree; iterating mixed object lists without checking kinds; scripts reading loose objects by id.","solutions":["Check obj.kind == gix_object::Kind::Commit before calling, or use try_to_commit_ref_iter() which returns Option.","Peel tags first with obj.peel_to_kind(gix_object::Kind::Commit)? to reach the underlying commit.","Handle the None from try_to_commit_ref_iter() with a proper error or branch."],"exampleFix":"// before\nlet iter = obj.to_commit_ref_iter(); // panics if not a commit\n// after\nlet Some(iter) = obj.try_to_commit_ref_iter() else {\n    anyhow::bail!(\"object {} is not a commit\", obj.id);\n};","handlingStrategy":"type-guard","validationCode":"if obj.kind == gix_object::Kind::Commit {\n    let iter = obj.to_commit_ref_iter();\n}","typeGuard":"fn as_commit_iter(obj: &gix::Object) -> Option<gix_object::CommitRefIter<'_>> { obj.try_to_commit_ref_iter() }","tryCatchPattern":null,"preventionTips":["Use try_to_commit_ref_iter() when the kind is uncertain.","Peel annotated tags before treating an object as a commit.","Validate kind early when reading user-supplied revisions."],"tags":["rust","panic","object-conversion","commit"],"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"}