{"record":{"id":"e4b8c554f694d11b","repo":"nautechsystems/nautilus_trader","slug":"socket-endpoint-cannot-be-empty","errorCode":null,"errorMessage":"Socket endpoint cannot be empty","messagePattern":"Socket endpoint cannot be empty","errorType":"validation","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/common/src/messages/system/socket.rs","lineNumber":28,"sourceCode":"//  distributed under the License is distributed on an \"AS IS\" BASIS,\n//  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n//  See the License for the specific language governing permissions and\n//  limitations under the License.\n// -------------------------------------------------------------------------------------------------\n\nuse std::{any::Any, fmt::Display};\n\nuse nautilus_core::{UUID4, UnixNanos};\nuse nautilus_model::identifiers::{ClientId, TraderId, Venue};\nuse ustr::Ustr;\n\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)]","sourceCodeStart":10,"sourceCodeEnd":46,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/common/src/messages/system/socket.rs#L10-L46","documentation":"socket_endpoint validates a socket endpoint name before converting it to a Ustr. An empty string carries no meaningful endpoint identity, so the validator rejects it immediately. This is a input-validation guard used by socket connect/reconnect commands.","triggerScenarios":"Calling socket_endpoint(\"\") or invoking a socket connect/reconnect API (live feature) with an empty endpoint string, e.g. from an unset config field.","commonSituations":"Live-trading config where the socket endpoint key was omitted or left as an empty string in YAML/env config; programmatic construction of reconnect commands with a default-empty value.","solutions":["Provide a non-empty endpoint string (letters, digits, '.', '-', '_') before calling the API.","Validate the config at load time: reject empty socket endpoint fields early with a clear message.","If the endpoint comes from an optional config value, use unwrap_or_default semantics only when a sensible default exists, otherwise error out at config load.","Check for empty-after-trim values: a whitespace-only endpoint may still be rejected downstream, so trim and validate yourself."],"exampleFix":"// before\nlet endpoint = config.endpoint.as_deref().unwrap_or(\"\");\nlet ep = socket_endpoint(endpoint)?;\n// after\nlet endpoint = config.endpoint.as_deref().filter(|s| !s.is_empty())\n    .ok_or_else(|| anyhow::anyhow!(\"socket endpoint must be configured\"))?;\nlet ep = socket_endpoint(endpoint)?;","handlingStrategy":"validation","validationCode":"fn endpoint_configured(s: Option<&str>) -> bool {\n    s.map(|v| !v.trim().is_empty()).unwrap_or(false)\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!(\"invalid socket endpoint '{endpoint}': {e}\"))?;","preventionTips":["Make endpoint a required, non-empty config field with load-time validation.","Trim env-sourced values before use.","Fail fast at config load, not at connect time."],"tags":["validation","network","socket","rust"],"backgroundTag":"empty-required-field","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"}