{"record":{"id":"66367f45b33f54da","repo":"GitoxideLabs/gitoxide","slug":"bug-need-a-commit","errorCode":null,"errorMessage":"BUG: need a commit","messagePattern":"BUG: need a commit","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"gix/src/object/mod.rs","lineNumber":170,"sourceCode":"        }\n    }\n\n    /// Sever the connection to the `Repository` and turn this instance into a standalone object.\n    pub fn detach(self) -> ObjectDetached {\n        self.into()\n    }\n}\n\n/// Conversions to detached, lower-level object types.\nimpl<'repo> Object<'repo> {\n    /// Obtain a fully parsed commit whose fields reference our data buffer,\n    ///\n    /// # Panic\n    ///\n    /// - this object is not a commit\n    /// - the commit could not be decoded\n    pub fn to_commit_ref(&self) -> gix_object::CommitRef<'_> {\n        self.try_to_commit_ref().expect(\"BUG: need a commit\")\n    }\n\n    /// Obtain a fully parsed commit whose fields reference our data buffer.\n    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","sourceCodeStart":152,"sourceCodeEnd":188,"githubUrl":"https://github.com/GitoxideLabs/gitoxide/blob/e73179060badf27222d790981fac3f84c1830a7e/gix/src/object/mod.rs#L152-L188","documentation":"Object::to_commit_ref() is a convenience wrapper around try_to_commit_ref() that expects decoding to succeed. It panics when the object's kind is not a commit or the commit data cannot be decoded, as documented in its # Panic section.","triggerScenarios":"Calling to_commit_ref() on an Object whose kind is a blob, tree, or tag; calling it on a malformed/corrupt commit object that fails to decode.","commonSituations":"Working with objects obtained from a rev-spec that resolved to a non-commit (e.g. a tag or tree); repositories with corrupted objects; assuming a short hash pointed at a commit.","solutions":["Check the object kind first: if obj.kind != gix_object::Kind::Commit, handle it or peel tags to a commit.","Use try_to_commit_ref() and handle the Result instead of panicking.","Peel the object to the desired kind via obj.peel_to_kind(gix_object::Kind::Commit)? before converting."],"exampleFix":"// before\nlet commit = obj.to_commit_ref(); // panics if not a commit\n// after\nlet commit = match obj.kind {\n    gix_object::Kind::Commit => obj.to_commit_ref(),\n    _ => obj.peel_to_kind(gix_object::Kind::Commit)?\n        .expect(\"peeled\")\n        .to_commit_ref(),\n};","handlingStrategy":"type-guard","validationCode":"if obj.kind == gix_object::Kind::Commit {\n    let commit = obj.to_commit_ref();\n}","typeGuard":"fn is_commit(obj: &gix::Object) -> bool { obj.kind == gix_object::Kind::Commit }","tryCatchPattern":null,"preventionTips":["Prefer try_to_commit_ref() in library-quality code.","Peel tags to commits before conversion.","Check Object::kind before any to_* conversion."],"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"}