nautechsystems/nautilus_trader · error · anyhow::Error
Socket endpoint cannot be empty
Error message
Socket endpoint cannot be empty
What it means
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.
Source
Thrown at crates/common/src/messages/system/socket.rs:28
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// -------------------------------------------------------------------------------------------------
use std::{any::Any, fmt::Display};
use nautilus_core::{UUID4, UnixNanos};
use nautilus_model::identifiers::{ClientId, TraderId, Venue};
use ustr::Ustr;
#[cfg(any(feature = "live", test))]
const ENDPOINT_MAX_LEN: usize = 128;
#[cfg(any(feature = "live", test))]
pub(crate) fn socket_endpoint(endpoint: &str) -> anyhow::Result<Ustr> {
if endpoint.is_empty() {
anyhow::bail!("Socket endpoint cannot be empty");
}
if endpoint.len() > ENDPOINT_MAX_LEN {
anyhow::bail!("Socket endpoint cannot exceed {ENDPOINT_MAX_LEN} bytes");
}
if !endpoint
.bytes()
.all(|byte| byte.is_ascii_alphanumeric() || matches!(byte, b'.' | b'-' | b'_'))
{
anyhow::bail!("Socket endpoint must contain only ASCII letters, digits, '.', '-', or '_'");
}
Ok(Ustr::from(endpoint))
}
/// Command requesting reconnect of one socket endpoint owned by one client.
#[repr(C)]View on GitHub (pinned to 18893faf8b)
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.
Example fix
// before
let endpoint = config.endpoint.as_deref().unwrap_or("");
let ep = socket_endpoint(endpoint)?;
// after
let endpoint = config.endpoint.as_deref().filter(|s| !s.is_empty())
.ok_or_else(|| anyhow::anyhow!("socket endpoint must be configured"))?;
let ep = socket_endpoint(endpoint)?; Defensive patterns
Strategy: validation
Validate before calling
fn endpoint_configured(s: Option<&str>) -> bool {
s.map(|v| !v.trim().is_empty()).unwrap_or(false)
} Type guard
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'_')) } Try / catch
let ep = socket_endpoint(endpoint)
.map_err(|e| anyhow::anyhow!("invalid socket endpoint '{endpoint}': {e}"))?; Prevention
- 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.
When it happens
Trigger: Calling socket_endpoint("") or invoking a socket connect/reconnect API (live feature) with an empty endpoint string, e.g. from an unset config field.
Common situations: 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.
Understand the failure class
Background: "must not be empty", "cannot be empty" — required-field validation errors across open-source libraries — this error's family across 41 libraries.
Related errors
- Socket endpoint cannot exceed {ENDPOINT_MAX_LEN} bytes
- Socket endpoint must contain only ASCII letters, digits, '.'
- Socket suffix cannot be empty: suffix is required for messag
- rate limiter decision lock poisoned
- {e}
AI-assisted analysis of nautechsystems/nautilus_trader@18893faf8b (2026-09-08).
Data as JSON: /api/errors/e4b8c554f694d11b.
Report an issue: GitHub.