{"record":{"id":"c59da7530406f423","repo":"vectordotdev/vector","slug":"referenced-schema-must-exist-in-definitions","errorCode":null,"errorMessage":"referenced schema must exist in definitions","messagePattern":"referenced schema must exist in definitions","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"lib/vector-config/src/schema/visitors/inline_single.rs","lineNumber":82,"sourceCode":"            })\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\n            root.definitions\n                .remove(&schema_def_name)\n                .expect(\"referenced schema must exist in definitions\");\n        }\n    }\n\n    fn visit_schema_object(\n        &mut self,\n        definitions: &mut Map<String, Schema>,\n        schema: &mut SchemaObject,\n    ) {\n        // Recursively visit this schema first.\n        visit::visit_schema_object(self, definitions, schema);\n\n        // If this schema has a schema reference, see if it's in our inline eligibility map. If so,\n        // we remove the referenced schema from the definitions, and then merge it into the current\n        // schema, after removing the `$ref` field.\n        if let Some(schema_ref) = schema.reference.as_ref().cloned() {\n            let schema_ref = get_cleaned_schema_reference(&schema_ref);\n            if self.eligible_to_inline.contains(schema_ref) {\n                let referenced_schema = definitions","sourceCodeStart":64,"sourceCodeEnd":100,"githubUrl":"https://github.com/vectordotdev/vector/blob/bdb87aeaa4c4ff27c0ba643c1c77b21bf2ef4013/lib/vector-config/src/schema/visitors/inline_single.rs#L64-L100","documentation":"After inlining a schema reference into all its usage sites, `visit_root_schema` removes the now-unused definition from `root.definitions` and asserts the entry exists. The panic fires if the definition was already removed — e.g. because inlining ran twice or the definition was deleted by another step between eligibility computation and removal.","triggerScenarios":"Running `visit_root_schema` (the single-ref inlining visitor) over a root schema where the target definition was already deleted: double invocation of the visitor, or another visitor in the pipeline removing definitions first.","commonSituations":"Applying the schema visitor pipeline twice to the same `RootSchema`; combining visitors that both prune definitions; unit-test fixtures calling the visitor repeatedly on shared state.","solutions":["Apply the schema transformation pipeline exactly once per root schema","Check for duplicate visitor registration in the schema-generation pipeline","Use `remove().is_some()` defensive checks locally if you control a fork, but upstream the fix via `entry()`/idempotent removal","Regenerate the schema from scratch rather than re-visiting a mutated schema"],"exampleFix":"// before (re-visiting mutated schema)\nvisitor.visit_root_schema(&mut schema);\nvisitor.visit_root_schema(&mut schema);\n// after\nvisitor.visit_root_schema(&mut schema);","handlingStrategy":"validation","validationCode":"fn assert_definitions_intact(root: &RootSchema, expected: &[&str]) -> Result<(), String> {\n    for name in expected {\n        if !root.definitions.contains_key(*name) {\n            return Err(format!(\"definition missing before inline pass: {name}\"));\n        }\n    }\n    Ok(())\n}","typeGuard":null,"tryCatchPattern":"if root.definitions.remove(&schema_def_name).is_none() {\n    tracing::warn!(referent = %schema_def_name, \"definition already removed; skipping\");\n}","preventionTips":["Apply the inlining visitor exactly once per root schema","Do not register multiple visitors that remove definitions","Assert pipeline idempotency in tests"],"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"}