{"record":{"id":"a2244eba2e2db982","repo":"GitoxideLabs/gitoxide","slug":"tried-to-use-as-commit-but-was","errorCode":null,"errorMessage":"Tried to use {} as commit, but was {}","messagePattern":"Tried to use (.+?) as commit, but was (.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"gix/src/object/mod.rs","lineNumber":96,"sourceCode":"        match self.try_into() {\n            Ok(blob) => blob,\n            Err(this) => panic!(\"Tried to use {} as blob, but was {}\", this.id, this.kind),\n        }\n    }\n\n    /// Transform this object into a tree, or panic if it is none.\n    pub fn into_tree(self) -> Tree<'repo> {\n        match self.try_into() {\n            Ok(tree) => tree,\n            Err(this) => panic!(\"Tried to use {} as tree, but was {}\", this.id, this.kind),\n        }\n    }\n\n    /// Transform this object into a commit, or panic if it is none.\n    pub fn into_commit(self) -> Commit<'repo> {\n        match self.try_into() {\n            Ok(commit) => commit,\n            Err(this) => panic!(\"Tried to use {} as commit, but was {}\", this.id, this.kind),\n        }\n    }\n\n    /// Transform this object into a tag, or panic if it is none.\n    pub fn into_tag(self) -> Tag<'repo> {\n        match self.try_into() {\n            Ok(tag) => tag,\n            Err(this) => panic!(\"Tried to use {} as tag, but was {}\", this.id, this.kind),\n        }\n    }\n\n    /// Transform this object into a commit, or return it as part of the `Err` if it is no commit.\n    pub fn try_into_commit(self) -> Result<Commit<'repo>, try_into::Error> {\n        self.try_into().map_err(|this: Self| try_into::Error {\n            id: this.id,\n            actual: this.kind,\n            expected: gix_object::Kind::Commit,\n        })","sourceCodeStart":78,"sourceCodeEnd":114,"githubUrl":"https://github.com/GitoxideLabs/gitoxide/blob/e73179060badf27222d790981fac3f84c1830a7e/gix/src/object/mod.rs#L78-L114","documentation":"This panic comes from `Object::into_commit()` in gix, the panic-based conversion of a generic `Object` handle into a `Commit`. The library throws it because the object is not a commit (its kind was Blob, Tree, or Tag). It mirrors the fallible `try_into_commit()` and its panic indicates the caller assumed the wrong object type.","triggerScenarios":"Calling `object.into_commit()` on an object loaded from an id that resolves to a blob, tree, or tag. Common with `repo.find_object(tree_id)?.into_commit()` or converting objects obtained from a loose iteration over mixed object kinds.","commonSituations":"Passing a tree or blob id where a commit was expected; handling a tag object without peeling it to the underlying commit; reading objects from pack/loose scans and assuming every entry is a commit.","solutions":["Guard with `object.kind == gix::object::Kind::Commit` before calling `into_commit()`.","Use `try_into_commit()` instead and handle the `Err`, which gives back the original object.","If the id may point at an annotated tag, peel first: `object.peel_to_kind(gix::object::Kind::Commit)`.","Confirm the id is a commit with `git cat-file -t <id>` before porting the logic."],"exampleFix":"// before\nlet commit = repo.find_object(id)?.into_commit();\n\n// after\nlet object = repo.find_object(id)?;\nlet commit = object.peel_to_kind(gix::object::Kind::Commit)?\n    .try_into_commit().expect(\"peeled to commit\");","handlingStrategy":"type-guard","validationCode":"let object = repo.find_object(commit_id)?;\nif object.kind != gix::object::Kind::Commit {\n    return Err(anyhow::anyhow!(\"id {} is {:?}, not a commit\", commit_id, object.kind));\n}","typeGuard":"fn as_commit(object: gix::Object<'_>) -> Option<gix::Commit<'_>> {\n    (object.kind == gix::object::Kind::Commit).then(|| object.try_into_commit().expect(\"kind checked\"))\n}","tryCatchPattern":"let commit = match object.try_into_commit() {\n    Ok(commit) => commit,\n    Err(obj) => return Err(anyhow::anyhow!(\"object {} was {:?}, not a commit\", obj.id, obj.kind)),\n};","preventionTips":["Check `object.kind == Kind::Commit` before `into_commit()`.","Peel tags with `peel_to_kind(Kind::Commit)` when ids may reference annotated tags.","Use `rev.peel_to_commit()` (or similar fallible peel APIs) when starting from refs."],"tags":["panic","git","object-model","type-mismatch"],"backgroundTag":"type-mismatch","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"}