quickwit-oss/quickwit · info
Instance should be of type T.
Error message
Instance should be of type T.
What it means
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.
Source
Thrown at quickwit/quickwit-common/src/type_map.rs:34
use std::collections::HashMap;
#[derive(Debug, Default)]
pub struct TypeMap(HashMap<TypeId, Box<dyn Any + Send + Sync>>);
impl TypeMap {
pub fn contains<T: Any + Send + Sync>(&self) -> bool {
self.0.contains_key(&TypeId::of::<T>())
}
pub fn insert<T: Any + Send + Sync>(&mut self, instance: T) {
self.0.insert(TypeId::of::<T>(), Box::new(instance));
}
pub fn get<T: Any + Send + Sync>(&self) -> Option<&T> {
self.0.get(&TypeId::of::<T>()).map(|instance| {
instance
.downcast_ref::<T>()
.expect("Instance should be of type T.")
})
}
pub fn get_mut<T: Any + Send + Sync>(&mut self) -> Option<&mut T> {
self.0.get_mut(&TypeId::of::<T>()).map(|instance| {
instance
.downcast_mut::<T>()
.expect("Instance should be of type T.")
})
}
}
View on GitHub (pinned to a39730c5cd)
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).
Defensive patterns
Strategy: type-guard
Validate before calling
let same_type = std::any::TypeId::of::<T>() == std::any::TypeId::of::<U>();
Type guard
fn is_type<T: 'static, U: 'static>(_v: &U) -> bool { std::any::TypeId::of::<T>() == std::any::TypeId::of::<U>() } Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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).
Understand the failure class
Background: "This is a bug, please report it": internal invariant violations, unreachable panics, and SNH errors explained — this error's family across 47 libraries.
Related errors
- node not found in pending
- OTP logs or traces do not support VRL transforms
- position of a Kafka partition should never be EOF
- position of a Kinesis shard should never be EOF
- trying to replace in progress message
AI-assisted analysis of quickwit-oss/quickwit@a39730c5cd (2026-09-08).
Data as JSON: /api/errors/02f7c1414bd95ba7.
Report an issue: GitHub.