{"record":{"id":"882e6582b993d4b8","repo":"vectordotdev/vector","slug":"path-must-end-with-a-key","errorCode":null,"errorMessage":"Path must end with a key.","messagePattern":"Path must end with a key\\.","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"lib/docs-renderer/src/renderer.rs","lineNumber":73,"sourceCode":"    ///\n    /// # Panics\n    ///\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 write<V: Into<Value>>(&mut self, path: &str, value: V) {\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.pop_back().expect(\"Path must end with a key.\");\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                if destination.contains_key(segment) {\n                    match destination.get_mut(segment) {\n                        Some(Value::Object(next)) => {\n                            destination = next;\n                            continue;\n                        }\n                        Some(_) => {\n                            panic!(\"Only leaf nodes should be allowed to be non-object values.\")\n                        }\n                        None => unreachable!(\"Already asserted that the given key exists.\"),\n                    }\n                } else {","sourceCodeStart":55,"sourceCodeEnd":91,"githubUrl":"https://github.com/vectordotdev/vector/blob/bdb87aeaa4c4ff27c0ba643c1c77b21bf2ef4013/lib/docs-renderer/src/renderer.rs#L55-L91","documentation":"`Renderer::write` in the docs-renderer splits a slash-delimited path and pops the last segment as the target map key; it panics if there is no such segment. A path with no trailing key (e.g. `\"/\"` or `\"\"`) has nowhere to write, so the operation is invalid by contract — paths must point at a concrete key below the root.","triggerScenarios":"Calling `write` with a path that has no key segment after splitting on `/`: `\"/\"` (root only), an empty string, or a path consisting solely of slashes.","commonSituations":"Typically a bug in docs-generation code that computes paths dynamically, e.g. joining components and producing a bare `/` for top-level entries, or template/config data missing a section name.","solutions":["Ensure every path passed to `write` includes at least one segment after the leading `/` (e.g. `/section/key` not `/section` or `/`)","Guard dynamic path construction: skip or special-case entries whose computed path ends at the root","Validate/trim paths before calling and reject root-only paths early","If the path should replace the whole document, use the appropriate root-level API instead of `write`"],"exampleFix":"// before\nrenderer.write(\"/\", value);\n// after\nif path_segments.len() >= 2 {\n    renderer.write(&path, value);\n}","handlingStrategy":"validation","validationCode":"fn is_writable_path(path: &str) -> bool {\n    path.split('/').any(|seg| !seg.is_empty())\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always build paths with at least one key segment","Avoid emitting root-only paths from dynamic doc generators","Validate paths before calling renderer APIs"],"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"}