spacedriveapp/spacedrive · error · anyhow::Error
Invalid instance name: {}
Error message
Invalid instance name: {} What it means
The --instance flag is validated by validate_instance_name (apps/cli/src/main.rs:26) as a path-traversal guard before it is used to build socket/data paths. It rejects empty strings, names longer than 64 characters, and any character that is not alphanumeric, '-' or '_'. The wrapper anyhow! re-exports the specific reason.
Source
Thrown at apps/cli/src/main.rs:248
Cloud,
/// Update CLI and daemon to latest version
Update {
/// Force update even if already on latest version
#[arg(long)]
force: bool,
},
}
#[tokio::main]
async fn main() -> Result<()> {
let cli = Cli::parse();
let data_dir = cli.data_dir.unwrap_or(sd_core::config::default_data_dir()?);
let instance = cli.instance;
// Validate instance name for security
if let Some(ref inst) = instance {
validate_instance_name(inst)
.map_err(|e| anyhow::anyhow!("Invalid instance name: {}", e))?;
}
let socket_addr = if let Some(inst) = &instance {
let port = 6970 + (inst.bytes().map(|b| b as u16).sum::<u16>() % 1000);
format!("127.0.0.1:{}", port)
} else {
"127.0.0.1:6969".to_string()
};
match cli.command {
Commands::Start { foreground } => {
crate::ui::print_compact_logo();
println!("Starting daemon...");
// Check if daemon is already running
let client = CoreClient::new(socket_addr.clone());
match client
.send_raw_request(&sd_core::infra::daemon::types::DaemonRequest::Ping)View on GitHub (pinned to 6dfeccf211)
Solutions
- Restrict the instance name to [A-Za-z0-9_-]{1,64}
- Strip or replace forbidden characters before invoking the CLI
- Remember the name also derives the port (6970 + sum of bytes % 1000), so keep it short and stable
Example fix
# before sd --instance 'work.laptop' status # after sd --instance work_laptop status
Defensive patterns
Strategy: validation
Validate before calling
fn valid_instance_name(s: &str) -> bool {
!s.is_empty()
&& s.len() <= 64
&& s.chars().all(|c| c.is_alphanumeric() || c == '-' || c == '_')
} Type guard
fn sanitize_instance_name(raw: &str) -> Option<String> {
let cleaned: String = raw.chars().map(|c| if c.is_alphanumeric() || c == '-' || c == '_' { c } else { '_' }).collect();
(!cleaned.is_empty() && cleaned.len() <= 64).then_some(cleaned)
} Try / catch
if let Err(reason) = validate_instance_name(&instance) {
eprintln!("Instance name '{}' rejected: {}", instance, reason);
std::process::exit(2); // usage error, do not retry
} Prevention
- Generate instance names from a fixed [a-z0-9-_] alphabet instead of free-form hostnames
- Validate at flag-parse time (clap value_parser) so failures get usage-style errors
- Remember the name determines the socket port; changing it later points the CLI at a different daemon
When it happens
Trigger: Passing --instance with '/', '.', spaces, or unicode; an empty value; a long hostname or generated ID exceeding 64 chars.
Common situations: Scripts interpolating user input, FQDNs, or container hostnames into --instance.
Related errors
- Path is required in non-interactive mode
- Failed to build action: {}
- Path must be a directory: {}
- Invalid time format: {}
- Invalid event type: {}
AI-assisted analysis of spacedriveapp/spacedrive@6dfeccf211 (2026-08-16).
Data as JSON: /api/errors/9a46d694330c0fa4.
Report an issue: GitHub.