vectordotdev/vector · error
stack was empty during pop
Error message
stack was empty during pop
What it means
`pop_schema_scope` on `OccurrenceVisitor` pops its schema-reference scope stack and asserts a scope existed. The panic fires when pop is called without a matching push, i.e. the visitor's scope stack is empty — a tracking invariant of the scoped traversal (push on entering a $ref, pop on exit) was broken.
Solutions
- Only drive scoped visitors through `visit_schema_object_scoped` / the standard traversal entry points
- Verify balanced push/pop pairs if you added custom traversal code
- Check the schema being visited for unexpected structure and reproduce with a minimal config
- Report upstream if a stock component config triggers it
Example fix
// before
visitor.pop_schema_scope();
visitor.visit_schema_object(...);
// after
visitor.push_schema_scope("MyDef");
visitor.visit_schema_object(...);
visitor.pop_schema_scope(); Defensive patterns
Strategy: try-catch
Validate before calling
if visitor.scope_stack_is_empty() {
return Err("cannot pop schema scope: stack empty".into());
} Try / catch
match visitor.try_pop_schema_scope() {
Ok(scope) => scope,
Err(e) => { tracing::error!("scope pop failed: {e}"); return Err(e); }
} Prevention
- Only drive scoped visitors through visit_schema_object_scoped
- Keep push/pop strictly paired in any custom traversal code
- Add a debug assertion that the stack is balanced at traversal exit
When it happens
Trigger: Traversal code calls `pop_schema_scope` more times than `push_schema_scope` was called — e.g. a schema object without a reference still triggers a pop, or the visitor is invoked outside the standard scoped traversal driver (`visit_schema_object_scoped`).
Common situations: Calling visitor methods directly instead of through the scoped traversal entry point; custom schema shapes (e.g. schemas at unexpected nesting) causing unbalanced push/pop in the traversal driver.
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
- stack was empty during pop
- all-of subschemas must be present here
- referenced schema must exist in definitions
- schema definition must exist
- schema definition must exist
AI-assisted analysis of vectordotdev/vector@bdb87aeaa4 (2026-09-16).
Data as JSON: /api/errors/9841f7ba2367cf39.
Report an issue: GitHub.
Appendix: source
Thrown at lib/vector-config/src/schema/visitors/inline_single.rs:170
visit_schema_object_scoped(self, definitions, schema);
if let Some(current_schema_ref) = schema.reference.as_ref() {
let current_schema_ref = get_cleaned_schema_reference(current_schema_ref);
*self
.occurrence_map
.entry(current_schema_ref.into())
.or_default() += 1;
}
}
}
impl ScopedVisitor for OccurrenceVisitor {
fn push_schema_scope<S: Into<SchemaReference>>(&mut self, scope: S) {
self.scope_stack.push(scope.into());
}
fn pop_schema_scope(&mut self) {
self.scope_stack.pop().expect("stack was empty during pop");
}
fn get_current_schema_scope(&self) -> &SchemaReference {
self.scope_stack.current().unwrap_or(&SchemaReference::Root)
}
}
fn get_schema_metadata_attr<'a>(schema: &'a SchemaObject, key: &str) -> Option<&'a Value> {
schema
.extensions
.get("_metadata")
.and_then(|metadata| metadata.get(key))
}
#[cfg(test)]
mod tests {
use serde_json::json;
use vector_config_common::schema::visit::Visitor;View on GitHub (pinned to bdb87aeaa4)