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

  1. Restrict the instance name to [A-Za-z0-9_-]{1,64}
  2. Strip or replace forbidden characters before invoking the CLI
  3. 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

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


AI-assisted analysis of spacedriveapp/spacedrive@6dfeccf211 (2026-08-16). Data as JSON: /api/errors/9a46d694330c0fa4. Report an issue: GitHub.