{"record":{"id":"02f7c1414bd95ba7","repo":"quickwit-oss/quickwit","slug":"instance-should-be-of-type-t","errorCode":null,"errorMessage":"Instance should be of type T.","messagePattern":"Instance should be of type T\\.","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"info","filePath":"quickwit/quickwit-common/src/type_map.rs","lineNumber":34,"sourceCode":"use std::collections::HashMap;\n\n#[derive(Debug, Default)]\npub struct TypeMap(HashMap<TypeId, Box<dyn Any + Send + Sync>>);\n\nimpl TypeMap {\n    pub fn contains<T: Any + Send + Sync>(&self) -> bool {\n        self.0.contains_key(&TypeId::of::<T>())\n    }\n\n    pub fn insert<T: Any + Send + Sync>(&mut self, instance: T) {\n        self.0.insert(TypeId::of::<T>(), Box::new(instance));\n    }\n\n    pub fn get<T: Any + Send + Sync>(&self) -> Option<&T> {\n        self.0.get(&TypeId::of::<T>()).map(|instance| {\n            instance\n                .downcast_ref::<T>()\n                .expect(\"Instance should be of type T.\")\n        })\n    }\n\n    pub fn get_mut<T: Any + Send + Sync>(&mut self) -> Option<&mut T> {\n        self.0.get_mut(&TypeId::of::<T>()).map(|instance| {\n            instance\n                .downcast_mut::<T>()\n                .expect(\"Instance should be of type T.\")\n        })\n    }\n}\n","sourceCodeStart":16,"sourceCodeEnd":46,"githubUrl":"https://github.com/quickwit-oss/quickwit/blob/a39730c5cdcd1a4fe798403737ae293999ea21f8/quickwit/quickwit-common/src/type_map.rs#L16-L46","documentation":"This panic fires in TypeMap::get when a value stored under a given TypeId fails to downcast to T. Because insertion uses the same TypeId::of::<T>() as lookup, the stored instance is always of type T, making this an impossible-state assertion guarding against a corrupted type map or a bug in the implementation. It exists so get can convert Option<&dyn Any> into Option<&T> via unwrap-style expect.","triggerScenarios":"Calling TypeMap::get::<T>() after inserting a value for type T. In correct usage this never panics; it only panics if the map internals were corrupted, the map was populated by code that stored mismatched types under the same TypeId, or a custom key-collision bug exists.","commonSituations":"Developers essentially never hit this in practice; if seen it indicates a custom or patched type_map implementation, misuse of the private API, or concurrency corruption. It typically appears while debugging quickwit's actor/extension plumbing (e.g. typed storage in actor contexts).","solutions":["Trust the invariant: if this panics, inspect the type_map.rs implementation and any code writing into the map for TypeId key corruption.","Verify only type_map::insert (which keys by TypeId::of::<T> and stores Box<dyn Any> of the same T) writes entries; no code bypasses it.","If reproducing, use get::<T>() only with the exact same type path/version used at insert time (different crate versions produce distinct TypeIds)."],"exampleFix":null,"handlingStrategy":"type-guard","validationCode":"let same_type = std::any::TypeId::of::<T>() == std::any::TypeId::of::<U>();","typeGuard":"fn is_type<T: 'static, U: 'static>(_v: &U) -> bool { std::any::TypeId::of::<T>() == std::any::TypeId::of::<U>() }","tryCatchPattern":null,"preventionTips":["Only insert into TypeMap via its typed insert API; never bypass with raw TypeId keys.","Use the exact same type path/crate version for insert and get."],"tags":["rust","internal-invariant","downcast","type-map"],"backgroundTag":"internal-invariant-violation","analyzedSha":"a39730c5cdcd1a4fe798403737ae293999ea21f8","analyzedAt":"2026-09-08T13:19:37.784Z","contentChangedAt":"2026-09-08T13:19:37.784Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}