{"record":{"id":"3839e63b4f8f164c","repo":"nautechsystems/nautilus_trader","slug":"socket-endpoint-must-contain-only-ascii-letters-d","errorCode":null,"errorMessage":"Socket endpoint must contain only ASCII letters, digits, '.', '-', or '_'","messagePattern":"Socket endpoint must contain only ASCII letters, digits, '\\.', '-', or '_'","errorType":"validation","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/common/src/messages/system/socket.rs","lineNumber":39,"sourceCode":"\n#[cfg(any(feature = \"live\", test))]\nconst ENDPOINT_MAX_LEN: usize = 128;\n\n#[cfg(any(feature = \"live\", test))]\npub(crate) fn socket_endpoint(endpoint: &str) -> anyhow::Result<Ustr> {\n    if endpoint.is_empty() {\n        anyhow::bail!(\"Socket endpoint cannot be empty\");\n    }\n\n    if endpoint.len() > ENDPOINT_MAX_LEN {\n        anyhow::bail!(\"Socket endpoint cannot exceed {ENDPOINT_MAX_LEN} bytes\");\n    }\n\n    if !endpoint\n        .bytes()\n        .all(|byte| byte.is_ascii_alphanumeric() || matches!(byte, b'.' | b'-' | b'_'))\n    {\n        anyhow::bail!(\"Socket endpoint must contain only ASCII letters, digits, '.', '-', or '_'\");\n    }\n\n    Ok(Ustr::from(endpoint))\n}\n\n/// Command requesting reconnect of one socket endpoint owned by one client.\n#[repr(C)]\n#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]\n#[cfg_attr(\n    feature = \"python\",\n    pyo3::pyclass(module = \"nautilus_trader.common\", from_py_object)\n)]\n#[cfg_attr(\n    feature = \"python\",\n    pyo3_stub_gen::derive::gen_stub_pyclass(module = \"nautilus_trader.common\")\n)]\npub struct ReconnectSocket {\n    pub trader_id: TraderId,","sourceCodeStart":21,"sourceCodeEnd":57,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/common/src/messages/system/socket.rs#L21-L57","documentation":"socket_endpoint restricts endpoint characters to ASCII letters, digits, '.', '-', and '_'. Any other byte (spaces, slashes, colons, '@', unicode, etc.) causes this error. The restriction keeps endpoints safe as identifiers in socket command routing.","triggerScenarios":"Calling socket_endpoint with strings containing ':' (URL schemes/ports), '/' (paths), whitespace, or non-ASCII characters — e.g. passing `tcp://host:7323` or `my endpoint`.","commonSituations":"Config values copied from connection strings or URLs, endpoints containing environment placeholders like `${HOST}` that were not substituted, or trailing whitespace/newline from env variables.","solutions":["Strip the URL scheme and port, keeping only the endpoint name portion composed of allowed characters.","Trim whitespace and ensure environment variable substitution happened before validation.","Sanitize the endpoint: replace disallowed characters ('/', ':', spaces) with '-' or '_' when deriving names from addresses.","Validate the character set at config-load time with your own pre-check to produce a friendlier error."],"exampleFix":"// before\nlet ep = socket_endpoint(\"tcp://my-host:7323\")?;\n// after\nlet ep = socket_endpoint(\"my-host\")?; // ASCII letters, digits, '.', '-', '_' only","handlingStrategy":"validation","validationCode":"fn endpoint_charset_ok(s: &str) -> bool {\n    s.bytes().all(|b| b.is_ascii_alphanumeric() || matches!(b, b'.' | b'-' | b'_'))\n}","typeGuard":"fn valid_endpoint(s: &str) -> bool { !s.is_empty() && s.len() <= 128 && s.bytes().all(|b| b.is_ascii_alphanumeric() || matches!(b, b'.' | b'-' | b'_')) }","tryCatchPattern":"let ep = socket_endpoint(endpoint)\n    .map_err(|e| anyhow::anyhow!(\"endpoint '{endpoint}' has invalid characters: {e}\"))?;","preventionTips":["Strip scheme/port from addresses before using them as endpoints.","Sanitize derived names by replacing '/', ':', spaces with '-' or '_'.","Trim and fully resolve env placeholders before validation."],"tags":["validation","socket","rust","input-sanitization"],"backgroundTag":"invalid-argument-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"}