{"record":{"id":"2ca673b1589332d5","repo":"GitoxideLabs/gitoxide","slug":"tried-to-use-as-blob-but-was","errorCode":null,"errorMessage":"Tried to use {} as blob, but was {}","messagePattern":"Tried to use (.+?) as blob, but was (.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"gix/src/object/mod.rs","lineNumber":80,"sourceCode":"    pub(crate) fn from_data(\n        id: impl Into<ObjectId>,\n        kind: Kind,\n        data: Vec<u8>,\n        repo: &'repo crate::Repository,\n    ) -> Self {\n        Object {\n            id: id.into(),\n            kind,\n            data,\n            repo,\n        }\n    }\n\n    /// Transform this object into a blob, or panic if it is none.\n    pub fn into_blob(self) -> Blob<'repo> {\n        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    }","sourceCodeStart":62,"sourceCodeEnd":98,"githubUrl":"https://github.com/GitoxideLabs/gitoxide/blob/e73179060badf27222d790981fac3f84c1830a7e/gix/src/object/mod.rs#L62-L98","documentation":"`gix::object::Object::into_blob()` converts a generic object handle into a `Blob`, panicking if the object is actually a tree, commit, or tag. The panic includes the object's id and kind ('Tried to use {id} as blob, but was {kind}') because the caller requested a kind conversion that does not match the underlying object.","triggerScenarios":"Calling `repo.find_object(id)?.into_blob()` where `id` points at a commit, tree, or tag; assuming a lookup result is a blob without checking `object.kind`; walking data (e.g. tree entries, rev-list output) and unconditionally calling `into_blob()`.","commonSituations":"Reading file contents from a tree entry whose id is a submodule (commit) or tree; passing a commit id from a ref into blob-reading code; scripts iterating mixed object kinds.","solutions":["Check `object.kind == gix_object::Kind::Blob` before calling `into_blob()`","Use `object.try_into_blob()?` and propagate the error instead of panicking","Match on `object.kind` and dispatch to `into_commit()`/`into_tree()`/`into_tag()` as appropriate","Verify the source of the id actually refers to a blob (e.g. a tree entry with blob mode)"],"exampleFix":"// before\nlet blob = repo.find_object(entry_id)?.into_blob(); // panics if tree/commit\n// after\nlet object = repo.find_object(entry_id)?;\nlet blob = object.try_into_blob().map_err(|o| anyhow::anyhow!(\"{} is a {:?}, not a blob\", o.id, o.kind))?;","handlingStrategy":"type-guard","validationCode":"if object.kind != gix_object::Kind::Blob {\n    return Err(anyhow::anyhow!(\"expected blob, got {:?}\", object.kind));\n}\nlet blob = object.into_blob();","typeGuard":"fn as_blob<'r>(o: gix::Object<'r>) -> Option<gix::objs::Blob<'r>> {\n    o.try_into().ok()\n}","tryCatchPattern":null,"preventionTips":["Check object.kind before any into_* conversion","Handle submodule (commit) and tree entries when reading trees","Prefer try_into_blob and propagate errors in library-style code"],"tags":["rust","panic","objects","blob","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"}