{"record":{"id":"3878e47176438333","repo":"nautechsystems/nautilus_trader","slug":"invalid-url-e","errorCode":null,"errorMessage":"Invalid URL: {e}","messagePattern":"Invalid URL: (.+?)","errorType":"validation","errorClass":"Error::Io(std::io::Error)","httpStatus":null,"severity":"error","filePath":"crates/network/src/socket/client.rs","lineNumber":284,"sourceCode":"            reconnect_attempt_count: 0,\n            state_sink,\n        })\n    }\n\n    /// Parses a URL into its socket address and request URL.\n    ///\n    /// Accepts either:\n    /// - Raw socket address: \"host:port\" → returns (\"host:port\", \"scheme://host:port\")\n    /// - Full URL: \"scheme://host:port/path\" → returns (\"host:port\", original URL)\n    ///\n    /// # Errors\n    ///\n    /// Returns an error if the URL is invalid or missing required components.\n    fn parse_socket_url(url: &str, mode: Mode) -> Result<(String, String), Error> {\n        if url.contains(\"://\") {\n            // URL with scheme (e.g., \"wss://host:port/path\")\n            let parsed = url.parse::<http::Uri>().map_err(|e| {\n                Error::Io(std::io::Error::new(\n                    std::io::ErrorKind::InvalidInput,\n                    format!(\"Invalid URL: {e}\"),\n                ))\n            })?;\n\n            let host = parsed.host().ok_or_else(|| {\n                Error::Io(std::io::Error::new(\n                    std::io::ErrorKind::InvalidInput,\n                    \"URL missing host\",\n                ))\n            })?;\n\n            let port = parsed\n                .port_u16()\n                .unwrap_or_else(|| match parsed.scheme_str() {\n                    Some(\"wss\" | \"https\") => 443,\n                    Some(\"ws\" | \"http\") => 80,\n                    _ => match mode {","sourceCodeStart":266,"sourceCodeEnd":302,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/network/src/socket/client.rs#L266-L302","documentation":"parse_socket_url validates a WebSocket/socket URL. If the string contains \"://\" it is parsed as an http::Uri; a malformed URI raises \"Invalid URL: {e}\" (InvalidInput io error). Related checks in the same function also reject missing host/port, but this specific error fires when the URL cannot be parsed as a URI at all.","triggerScenarios":"Passing a URL with an invalid scheme or characters (spaces, unencoded non-ASCII, stray brackets) to a network socket client config — e.g. ws_url=\"wss:/host:port\" (single slash), \"wss://host :443\", or a URL with embedded credentials in the wrong place.","commonSituations":"Typo'd scheme or missing slash in a config file/env var; copy-pasting a URL with trailing whitespace or quotes; unencoded special characters (spaces, unicode) from templating; mistakenly passing a bare hostname while thinking \"://\" was present.","solutions":["Validate the URL before constructing the client: it must parse as http::Uri and include scheme, host, and port.","Trim whitespace/quotes and percent-encode special characters in the URL.","Use the correct scheme (ws:// or wss://) with the full authority, e.g. wss://host:port/path.","Check the config source (env var, YAML) for interpolated values that broke the URL.","If credentials are needed, put them in headers/options, not mangled into the URL string."],"exampleFix":"// before\nlet url = std::env::var(\"WS_URL\")?;           // \"wss://host :443\" -> Invalid URL\nlet client = SocketClient::new(url, mode);\n// after\nlet url = std::env::var(\"WS_URL\")?.trim().to_string();\nurl.parse::<http::Uri>().expect(\"valid ws url\");\nlet client = SocketClient::new(url, mode);","handlingStrategy":"validation","validationCode":"fn valid_socket_url(url: &str) -> bool {\n    url.trim().parse::<http::Uri>().map(|u| {\n        u.scheme_str().is_some() && u.host().is_some()\n    }).unwrap_or(false)\n}","typeGuard":null,"tryCatchPattern":"let url = config.ws_url.trim();\nif !valid_socket_url(url) {\n    anyhow::bail!(\"config ws_url is not a valid URI: {url:?}\");\n}\nlet client = SocketClient::new(url.to_string(), mode);","preventionTips":["Validate ws URLs (scheme://host:port/path) at config-load time","Trim whitespace and strip stray quotes from env/config values","Percent-encode special characters instead of embedding them raw","Prefer wss:// in production and include an explicit port when non-default"],"tags":["network","websocket","url","configuration"],"backgroundTag":"invalid-url-format","analyzedSha":"18893faf8b356be3320add8de2f861b0b647cf06","analyzedAt":"2026-09-08T20:49:34.690Z","contentChangedAt":"2026-09-08T20:49:34.690Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}