vectordotdev/vector · error
invalid parts
Error message
invalid parts
What it means
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.
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.
Example fix
// before
let uri = Uri::from_parts(parts).expect("invalid parts");
// after
let uri = Uri::from_parts(parts.clone())
.map_err(|e| crate::Error::from(format!("invalid endpoint URI {:?}: {}", parts, e)))?; Defensive patterns
Strategy: validation
Validate before calling
// validate before building the endpoint
assert!(endpoint_str.starts_with("http://") || endpoint_str.starts_with("https://"));
Uri::from_str(&endpoint_str).map_err(|e| format!("invalid endpoint URI: {e}"))?; Try / catch
match Uri::from_parts(parts) { Ok(u) => u, Err(e) => return Err(ConfigError::InvalidUri(e)) } Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: "Invalid URL" errors: why new URL(), URI.parse, and reqwest::Url reject your string — missing scheme, whitespace, and bad path format — this error's family across 39 libraries.
Related errors
- a valid HTTP/1 URI is valid as an HTTP URI
- a validated HTTP endpoint is a valid `http 1` URI
- error creating request
- error creating request
- building HTTP request failed unexpectedly
AI-assisted analysis of vectordotdev/vector@bdb87aeaa4 (2026-09-16).
Data as JSON: /api/errors/1f06e986ad15dddc.
Report an issue: GitHub.
Appendix: source
Thrown at src/sinks/util/uri.rs:47
impl UriSerde {
/// `Uri` supports incomplete URIs such as "/test", "example.com", etc.
/// This function fills in empty scheme with HTTP,
/// and empty authority with "127.0.0.1".
pub fn with_default_parts(&self) -> Self {
let mut parts = self.uri.clone().into_parts();
if parts.scheme.is_none() {
parts.scheme = Some(Scheme::HTTP);
}
if parts.authority.is_none() {
parts.authority = Some(Authority::from_static("127.0.0.1"));
}
if parts.path_and_query.is_none() {
// just an empty `path_and_query`,
// but `from_parts` will fail without this.
parts.path_and_query = Some(PathAndQuery::from_static(""));
}
let uri = Uri::from_parts(parts).expect("invalid parts");
Self {
uri,
auth: self.auth.clone(),
}
}
/// Creates a new instance of `UriSerde` by appending a path to the existing one.
pub fn append_path(&self, path: &str) -> crate::Result<Self> {
let uri = self.uri.to_string();
let self_path = uri.trim_end_matches('/');
let other_path = path.trim_start_matches('/');
let path = format!("{self_path}/{other_path}");
let uri = path.parse::<Uri>()?;
Ok(Self {
uri,
auth: self.auth.clone(),
})
}View on GitHub (pinned to bdb87aeaa4)