spacedriveapp/spacedrive · critical · anyhow::Error

Cannot set key: {}

Error message

Cannot set key: {}

What it means

Wrapper error thrown when NetworkingService::start() fails during start_networking. Notably, the code casts an Arc pointer to *mut and calls start() through unsafe, justified by a comment that start() runs only once during initialization; the wrapped error is the underlying start failure, not the cast itself. If init (error 216) already failed, self.networking is None and start_networking silently does nothing — so reaching this error means creation succeeded but startup did not.

Source

Thrown at apps/cli/src/domains/config/mod.rs:74

					.current_library_id
					.map(|id| id.to_string())
					.unwrap_or_else(|| "(not set)".to_string()),
				"update.repo" => config.update.repo.clone(),
				"update.channel" => config.update.channel.clone(),
				_ => return Err(anyhow::anyhow!("Unknown config key: {}", key)),
			};
			println!("{}", value);
		}
		ConfigCmd::Set { key, value } => match key.as_str() {
			"update.repo" => {
				config.set_update_repo(value.clone(), &data_dir)?;
				println!("Set update.repo = {}", value);
			}
			"update.channel" => {
				config.set_update_channel(value.clone(), &data_dir)?;
				println!("Set update.channel = {}", value);
			}
			_ => return Err(anyhow::anyhow!("Cannot set key: {}", key)),
		},
	}

	Ok(())
}

View on GitHub (pinned to 6dfeccf211)

Solutions

  1. Read the inner error after the colon for the failing bind/discovery step.
  2. Ensure no second sd-daemon instance is running (check process list / socket files).
  3. Verify the required ports/interfaces are available and firewall rules allow them.
  4. Retry startup once the network interface is up (init succeeded, so only start() needs to re-run).
Defensive patterns

Strategy: retry

Validate before calling

// Only attempt start when creation succeeded and no other instance holds the port.
if services.networking().is_none() {
    return Err(anyhow::anyhow!("networking not initialized; run init first"));
}

Try / catch

// Retry start a bounded number of times for boot-order races (interface not yet up).
let mut attempt = 0;
loop {
    match services.start_networking().await {
        Ok(()) => break,
        Err(e) if attempt < 3 => {
            attempt += 1;
            tokio::time::sleep(std::time::Duration::from_secs(2_u64.pow(attempt))).await;
        }
        Err(e) => return Err(e),
    }
}

Prevention

When it happens

Trigger: Calling start_networking after successful creation, where the p2p endpoint fails to bind/discover — occupied ports, network interfaces unavailable at startup, firewall blocking the listen socket, or relay/discovery unreachable.

Common situations: Another daemon instance already bound the port; container with restrictive network config; system boot ordering where networking starts before interfaces are up; corporate firewall blocking discovery endpoints.

Related errors


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