{"record":{"id":"75d0808e3d5c8e55","repo":"vectordotdev/vector","slug":"schema-definition-must-exist","errorCode":null,"errorMessage":"schema definition must exist","messagePattern":"schema definition must exist","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"lib/vector-config/src/schema/visitors/inline_single.rs","lineNumber":61,"sourceCode":"        let occurrence_map = occurrence_visitor.occurrence_map;\n\n        self.eligible_to_inline = occurrence_map\n            .into_iter()\n            // Filter out any schemas which have more than one occurrence, as naturally, we're\n            // trying to inline single-use schema references. :)\n            .filter_map(|(def_name, occurrences)| (occurrences == 1).then_some(def_name))\n            // However, we'll also filter out some specific schema definitions which are only\n            // referenced once, specifically: component base types and component types themselves.\n            //\n            // We do this as a lot of the tooling that parses the schema to generate documentation,\n            // and the like, depends on these schemas existing in the top-level definitions for easy\n            // lookup.\n            .filter(|def_name| {\n                let schema = root\n                    .definitions\n                    .get(def_name.as_ref())\n                    .and_then(Schema::as_object)\n                    .expect(\"schema definition must exist\");\n\n                is_inlineable_schema(def_name.as_ref(), schema)\n            })\n            .map(|s| s.as_ref().to_string())\n            .collect::<HashSet<_>>();\n\n        // Now run our own visitor logic, which will use the inline eligibility to determine if a\n        // schema reference in a being-visited schema should be replaced inline with the original\n        // referenced schema, in turn removing the schema definition.\n        visit::visit_root_schema(self, root);\n\n        // Now remove all of the definitions for schemas that were eligible for inlining.\n        for schema_def_name in self.eligible_to_inline.drain() {\n            debug!(\n                referent = schema_def_name,\n                \"Removing schema definition from root schema.\"\n            );\n","sourceCodeStart":43,"sourceCodeEnd":79,"githubUrl":"https://github.com/vectordotdev/vector/blob/bdb87aeaa4c4ff27c0ba643c1c77b21bf2ef4013/lib/vector-config/src/schema/visitors/inline_single.rs#L43-L79","documentation":"While collecting definitions eligible for inlining, `visit_root_schema` looks up each candidate `$ref` name in the root schema's `definitions` map and asserts it exists. The panic fires when a definition name appears in the inline-candidate list but is missing from `root.definitions`, meaning the root schema's definitions were mutated or built inconsistently.","triggerScenarios":"Calling `visit_root_schema` on a `RootSchema` whose `definitions` map lacks an entry referenced by an earlier enumeration pass — e.g. the definitions were moved/drained before this visitor runs, or a composed visitor pipeline mutated definitions out of order.","commonSituations":"Chaining schema visitors in a non-standard order (running inline_single after another visitor that removes definitions); version skew between vector-config crates that changed visitor ordering.","solutions":["Ensure visitors that mutate `definitions` run in the intended order (inline_single's own visiting before any removal-based visitor)","Check that no other code drains/moves `root.definitions` before `visit_root_schema`","Pin consistent versions of vector-config-related crates in the workspace","Reproduce with a minimal `RootSchema` and add debug logging of definition names"],"exampleFix":"// before (wrong order)\nschema_pipeline.push(RemovingVisitor::default());\nschema_pipeline.push(InlineSingleVisitor::default());\n// after\nschema_pipeline.push(InlineSingleVisitor::default());\nschema_pipeline.push(RemovingVisitor::default());","handlingStrategy":"validation","validationCode":"fn validate_refs_resolve(root: &RootSchema) -> Result<(), String> {\n    for name in root.definitions.keys() {\n        if !root.definitions.contains_key(name) {\n            return Err(format!(\"dangling schema definition: {name}\"));\n        }\n    }\n    Ok(())\n}","typeGuard":"fn definition_exists<'a>(root: &'a RootSchema, name: &str) -> Option<&'a Schema> { root.definitions.get(name) }","tryCatchPattern":"let schema = root.definitions.get(def_name.as_ref()).ok_or_else(||\n    anyhow::anyhow!(\"schema definition {def_name:?} missing from root definitions\"))?;","preventionTips":["Run visitor pipelines in the documented order (inline before prune)","Never drain or move root.definitions before visiting","Use a fresh RootSchema per generation; avoid re-visiting mutated schemas"],"tags":["rust","schema-generation","json-schema"],"backgroundTag":"resource-not-found","analyzedSha":"bdb87aeaa4c4ff27c0ba643c1c77b21bf2ef4013","analyzedAt":"2026-09-16T02:53:35.741Z","contentChangedAt":"2026-09-16T02:53:35.741Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}