spacedriveapp/spacedrive · error · anyhow::Error

Failed to serialize sync request: {}

Error message

Failed to serialize sync request: {}

What it means

serde_json::to_vec(&request) failed while serializing the outgoing SyncMessage. SyncMessage variants are plain data, so this only happens when a variant contains a type whose Serialize impl can fail (for example a map with non-string keys) or the enum shape changed incompatibly. In practice this is a programming or version-skew bug, not an environmental failure.

Source

Thrown at core/src/service/network/transports/sync.rs:261

				use crate::service::network::core::event_loop::EventLoopCommand;
				let _ = cmd_sender.send(EventLoopCommand::TrackOutboundConnection {
					node_id,
					conn: new_conn.clone(),
				});
			}

			new_conn
		};

		// Open bidirectional stream
		let (mut send, mut recv) = conn
			.open_bi()
			.await
			.map_err(|e| anyhow::anyhow!("Failed to open bidirectional stream: {}", e))?;

		// Serialize and send request
		let req_bytes = serde_json::to_vec(&request)
			.map_err(|e| anyhow::anyhow!("Failed to serialize sync request: {}", e))?;

		let len = req_bytes.len() as u32;
		send.write_all(&len.to_be_bytes())
			.await
			.map_err(|e| anyhow::anyhow!("Failed to send length: {}", e))?;
		send.write_all(&req_bytes)
			.await
			.map_err(|e| anyhow::anyhow!("Failed to send request: {}", e))?;

		// Properly close send stream
		send.finish()
			.map_err(|e| anyhow::anyhow!("Failed to finish stream: {}", e))?;

		debug!("Sync request sent, waiting for response...");

		// Read response with timeout
		let result = timeout(Duration::from_secs(60), async {
			let mut len_buf = [0u8; 4];

View on GitHub (pinned to 6dfeccf211)

Solutions

  1. Inspect the SyncMessage variant being sent for types whose Serialize can error and replace them with JSON-safe types
  2. Add a unit test that round-trips every SyncMessage variant through serde_json::to_vec and from_slice
  3. Gate protocol changes behind a version handshake so mismatched peers reject cleanly instead of failing mid-serialize
Defensive patterns

Strategy: try-catch

Try / catch

match serde_json::to_vec(&request) {
    Err(e) => {
        error!(error = %e, "SyncMessage failed to serialize, this is a code bug");
        return Err(e.into());
    }
    Ok(bytes) => bytes,
}

Prevention

When it happens

Trigger: A newly added SyncMessage variant carries a non-JSON-serializable field; two peers built from different commits exchange message shapes the sender cannot encode.

Common situations: Almost never seen in production; appears during protocol development right after editing the SyncMessage enum.

Related errors


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