{"record":{"id":"c82d5f9fbaa3c2dc","repo":"vectordotdev/vector","slug":"path-cannot-point-directly-to-the-root-use-clear-instead","errorCode":null,"errorMessage":"Path cannot point directly to the root. Use `clear` instead.","messagePattern":"Path cannot point directly to the root\\. Use `clear` instead\\.","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"lib/docs-renderer/src/renderer.rs","lineNumber":134,"sourceCode":"    ///\n    /// If the path does not start with a forward slash, this method will panic. Likewise, if the\n    /// path is _only_ a forward slash (aka there is no segment to describe the key within the\n    /// object to write the value to), this method will panic.\n    ///\n    /// If any nested object within the path does not yet exist, it will be created. If any segment,\n    /// other than the leaf segment, points to a value that is not an object/map, this method will\n    /// panic.\n    pub fn delete(&mut self, path: &str) -> bool {\n        if !path.starts_with('/') {\n            panic!(\"Paths must always start with a leading forward slash (`/`).\");\n        }\n\n        self.with_mut_object(|map| {\n            // Split the path, and take the last element as the actual map key to write to.\n            let mut segments = path.split('/').collect::<VecDeque<_>>();\n            let key = segments\n                .pop_back()\n                .expect(\"Path cannot point directly to the root. Use `clear` instead.\");\n\n            // Iterate over the remaining elements, traversing into the root object one level at a\n            // time, based on using `token` as the map key. If there's no map at the given key,\n            // we'll create one. If there's something other than a map, we'll panic.\n            let mut destination = map;\n            while let Some(segment) = segments.pop_front() {\n                match destination.get_mut(segment) {\n                    Some(Value::Object(next)) => {\n                        destination = next;\n                        continue;\n                    }\n                    Some(_) => panic!(\"Only leaf nodes should be allowed to be non-object values.\"),\n                    // If the next segment doesn't exist, there's nothing for us to delete, so return `false`.\n                    None => return false,\n                }\n            }\n\n            destination.remove(key).is_some()","sourceCodeStart":116,"sourceCodeEnd":152,"githubUrl":"https://github.com/vectordotdev/vector/blob/bdb87aeaa4c4ff27c0ba643c1c77b21bf2ef4013/lib/docs-renderer/src/renderer.rs#L116-L152","documentation":"`Renderer::delete` pops the last path segment as the key to delete and panics if none exists. Deleting requires a concrete key; a path pointing directly at the document root has nothing to remove, hence the message telling callers to use `clear` instead.","triggerScenarios":"Calling `delete` with a root-only path: `\"/\"`, an empty string, or any path with no segments after splitting on `/`.","commonSituations":"Dynamic deletion logic that computes paths from data and occasionally produces the bare root path, or a config/template that names no section to delete.","solutions":["Call `clear` instead when the intent is to remove the entire document","Ensure computed paths always end in a key before calling `delete`","Add a pre-check that skips root-only paths or routes them to `clear`","Trim and validate path input (require at least one non-empty segment)"],"exampleFix":"// before\nrenderer.delete(\"/\");\n// after\nif path == \"/\" { renderer.clear(); } else { renderer.delete(&path); }","handlingStrategy":"validation","validationCode":"fn route_delete(renderer: &Renderer, path: &str) {\n    if path.split('/').all(|s| s.is_empty()) {\n        renderer.clear();\n    } else {\n        renderer.delete(path);\n    }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use `clear` for root-level deletion","Never pass empty or `/` paths to `delete`","Validate computed paths before destructive renderer calls"],"tags":["panic","docs","path","renderer"],"backgroundTag":"invalid-path-expression","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"}