{"record":{"id":"1ffb358c87a90a3c","repo":"vectordotdev/vector","slug":"should-not-fail-to-build-uri","errorCode":null,"errorMessage":"should not fail to build URI","messagePattern":"should not fail to build URI","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/components/validation/util.rs","lineNumber":34,"sourceCode":"    /// Gets the socket address.\n    ///\n    /// This is typically used when actually binding a socket to use for listening for connections\n    /// as a gRPC server.\n    pub const fn as_socket_addr(&self) -> SocketAddr {\n        self.addr\n    }\n\n    /// Gets the fully-qualified endpoint address.\n    ///\n    /// This is a URI in the form of `http://<socket address>/`. The scheme and path are hard-coded.\n    pub fn as_uri(&self) -> Uri {\n        let addr_str = self.addr.to_string();\n        Uri::builder()\n            .scheme(\"http\")\n            .authority(addr_str)\n            .path_and_query(\"/\")\n            .build()\n            .expect(\"should not fail to build URI\")\n    }\n}\n\nimpl From<SocketAddr> for GrpcAddress {\n    fn from(addr: SocketAddr) -> Self {\n        Self { addr }\n    }\n}\n\nimpl fmt::Display for GrpcAddress {\n    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {\n        self.addr.fmt(f)\n    }\n}\n","sourceCodeStart":16,"sourceCodeEnd":49,"githubUrl":"https://github.com/vectordotdev/vector/blob/bdb87aeaa4c4ff27c0ba643c1c77b21bf2ef4013/src/components/validation/util.rs#L16-L49","documentation":"`GrpcAddress::as_uri` builds an http:// URI from a SocketAddr with scheme, authority, and a fixed \"/\" path. Since both parts come from a well-formed SocketAddr, construction cannot fail in practice, so failure is asserted with `expect(\"should not fail to build URI\")`.","triggerScenarios":"Calling `as_uri` (directly or via build_output_edge, from_address, or attach_to_config) with an address whose string form is rejected by `http::Uri` building — practically only from a corrupted/oversized SocketAddr string.","commonSituations":"Setting up the validation gRPC output edge during vector validate runs; exotic SocketAddr implementations; IPv6 addresses rendering in an unexpected form after custom Display overrides.","solutions":["Verify no custom Display/ToSocketAddrs wrapper alters the address string before URI construction.","Update the http crate if a version bug rejects valid authority strings.","File an upstream bug with the address value if you can reproduce a failure with a standard SocketAddr."],"exampleFix":null,"handlingStrategy":"fallback","validationCode":"let uri = http::Uri::builder().scheme(\"http\").authority(addr.to_string()).path_and_query(\"/\").build(); assert!(uri.is_ok(), \"address {:?} did not produce a valid URI\", addr);","typeGuard":"fn is_valid_authority(addr: &SocketAddr) -> bool { !addr.to_string().is_empty() && addr.to_string().len() < 256 }","tryCatchPattern":"match build_uri(addr) { Ok(uri) => uri, Err(e) => { log::error!(\"URI build failed: {e}\"); return; } }  // if you own the code; otherwise this is an upstream bug","preventionTips":["Use standard SocketAddr values from Tokio's bind/connect results.","Keep the http crate up to date.","Add a unit test asserting as_uri succeeds for IPv4 and IPv6 loopback addresses."],"tags":["uri","grpc","internal-invariant"],"backgroundTag":"internal-invariant-violation","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"}