{"record":{"id":"d8d9a57cf747b25c","repo":"GitoxideLabs/gitoxide","slug":"tried-to-use-as-tree-but-was","errorCode":null,"errorMessage":"Tried to use {} as tree, but was {}","messagePattern":"Tried to use (.+?) as tree, but was (.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"gix/src/object/mod.rs","lineNumber":88,"sourceCode":"            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    }\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    }","sourceCodeStart":70,"sourceCodeEnd":106,"githubUrl":"https://github.com/GitoxideLabs/gitoxide/blob/e73179060badf27222d790981fac3f84c1830a7e/gix/src/object/mod.rs#L70-L106","documentation":"This panic comes from `Object::into_tree()` in gix, a non-fallible convenience API that converts a generic `Object` handle into a `Tree`. The library throws it because the object the handle points to is not actually a tree (its kind was Blob, Commit, or Tag). Since `into_tree` is deliberately a panic-based variant of `try_into_tree`, misuse is a caller logic bug rather than a recoverable library error.","triggerScenarios":"Calling `repo.find_object(id)?.into_tree()` (or `object.into_tree()`) when the object id resolves to a blob, commit, or tag instead of a tree. Typically happens after resolving an abbreviated id, a ref name, or iterating mixed objects without checking `object.kind`.","commonSituations":"Passing a commit id (e.g. from `HEAD`) where a tree id was expected; forgetting to call `.peel_to_tree()` first; iterating tree entries that reference blobs and blindly converting each object; using a tag object id directly instead of peeling it.","solutions":["Check the object kind before converting: only call `into_tree()` when `object.kind == gix::object::Kind::Tree`.","Use the fallible variant `try_into_tree()` and handle the `Err` case, which returns the original object instead of panicking.","If starting from a rev/ref, peel explicitly with `rev.peel_to_tree()` (or `object.peel_to_kind(gix::object::Kind::Tree)`) to resolve tags/commits down to their tree.","Verify the id being passed actually denotes a tree (e.g. `git cat-file -t <id>` returns `tree`)."],"exampleFix":"// before\nlet tree = repo.find_object(id)?.into_tree();\n\n// after\nlet object = repo.find_object(id)?;\nlet tree = match object.kind {\n    gix::object::Kind::Tree => object.try_into_tree().expect(\"kind checked as tree\"),\n    _ => object.peel_to_kind(gix::object::Kind::Tree)?.try_into_tree().expect(\"peeled to tree\"),\n};","handlingStrategy":"type-guard","validationCode":"let object = repo.find_object(tree_id)?;\nif object.kind != gix::object::Kind::Tree {\n    return Err(anyhow::anyhow!(\"id {} is {:?}, not a tree\", tree_id, object.kind));\n}","typeGuard":"fn as_tree(object: gix::Object<'_>) -> Option<gix::Tree<'_>> {\n    (object.kind == gix::object::Kind::Tree).then(|| object.try_into_tree().expect(\"kind checked\"))\n}","tryCatchPattern":"// Prefer the fallible API instead of catching a panic\nlet tree = match object.try_into_tree() {\n    Ok(tree) => tree,\n    Err(obj) => return Err(anyhow::anyhow!(\"object {} was {:?}, not a tree\", obj.id, obj.kind)),\n};","preventionTips":["Always check `object.kind` before any `into_*` conversion.","Prefer `try_into_tree()`/`peel_to_tree()` over the panicking `into_tree()` in production code.","Peel refs and tags to the expected kind (`peel_to_kind`) before operating on trees."],"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"}