{"record":{"id":"1f06e986ad15dddc","repo":"vectordotdev/vector","slug":"invalid-parts","errorCode":null,"errorMessage":"invalid parts","messagePattern":"invalid parts","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/sinks/util/uri.rs","lineNumber":47,"sourceCode":"\nimpl UriSerde {\n    /// `Uri` supports incomplete URIs such as \"/test\", \"example.com\", etc.\n    /// This function fills in empty scheme with HTTP,\n    /// and empty authority with \"127.0.0.1\".\n    pub fn with_default_parts(&self) -> Self {\n        let mut parts = self.uri.clone().into_parts();\n        if parts.scheme.is_none() {\n            parts.scheme = Some(Scheme::HTTP);\n        }\n        if parts.authority.is_none() {\n            parts.authority = Some(Authority::from_static(\"127.0.0.1\"));\n        }\n        if parts.path_and_query.is_none() {\n            // just an empty `path_and_query`,\n            // but `from_parts` will fail without this.\n            parts.path_and_query = Some(PathAndQuery::from_static(\"\"));\n        }\n        let uri = Uri::from_parts(parts).expect(\"invalid parts\");\n        Self {\n            uri,\n            auth: self.auth.clone(),\n        }\n    }\n\n    /// Creates a new instance of `UriSerde` by appending a path to the existing one.\n    pub fn append_path(&self, path: &str) -> crate::Result<Self> {\n        let uri = self.uri.to_string();\n        let self_path = uri.trim_end_matches('/');\n        let other_path = path.trim_start_matches('/');\n        let path = format!(\"{self_path}/{other_path}\");\n        let uri = path.parse::<Uri>()?;\n        Ok(Self {\n            uri,\n            auth: self.auth.clone(),\n        })\n    }","sourceCodeStart":29,"sourceCodeEnd":65,"githubUrl":"https://github.com/vectordotdev/vector/blob/bdb87aeaa4c4ff27c0ba643c1c77b21bf2ef4013/src/sinks/util/uri.rs#L29-L65","documentation":"with_default_parts builds an http::Uri from URI parts and calls Uri::from_parts(...).expect(\"invalid parts\"). from_parts fails when the parts combination is not a valid URI (e.g. scheme without authority, or invalid path/query/authority). The code defensively sets path_and_query to Some(\"\") because from_parts rejects a None path_and_query, but other invalid combinations still panic.","triggerScenarios":"Calling with_default_parts on an Endpoint whose parts combine invalidly — e.g. a scheme set without an authority, or an authority containing characters illegal in a URI — while preparing a URI for healthcheck.","commonSituations":"A sink endpoint configured with a malformed address (missing host, bad port, stray characters) that slips past earlier parsing; constructing endpoints programmatically from incomplete user config.","solutions":["Validate the endpoint address (scheme + host present, legal characters) before constructing the Endpoint.","Replace the expect with error propagation: match Uri::from_parts(parts) and return a crate::Error describing the bad URI.","Use Uri::from_str on the full endpoint string instead of assembling parts manually when possible."],"exampleFix":"// before\nlet uri = Uri::from_parts(parts).expect(\"invalid parts\");\n// after\nlet uri = Uri::from_parts(parts.clone())\n    .map_err(|e| crate::Error::from(format!(\"invalid endpoint URI {:?}: {}\", parts, e)))?;","handlingStrategy":"validation","validationCode":"// validate before building the endpoint\nassert!(endpoint_str.starts_with(\"http://\") || endpoint_str.starts_with(\"https://\"));\nUri::from_str(&endpoint_str).map_err(|e| format!(\"invalid endpoint URI: {e}\"))?;","typeGuard":null,"tryCatchPattern":"match Uri::from_parts(parts) { Ok(u) => u, Err(e) => return Err(ConfigError::InvalidUri(e)) }","preventionTips":["Parse user-provided endpoints with Uri::from_str at config load time.","Require scheme and host in endpoint configuration schemas.","Reject endpoint strings with whitespace or unencoded characters early."],"tags":["rust","panic","uri","http"],"backgroundTag":"invalid-url-format","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"}