linera-io/linera-protocol · error

Failed to parse {spawn_mode_name} as a spawn_mode

Error message

Failed to parse {spawn_mode_name} as a spawn_mode

What it means

When parsing a rocksdb storage config string of the form rocksdb:directory:spawn_mode[:namespace], StorageConfig::from_str matches the spawn_mode token against the allowed values. Only 'spawn_blocking', 'block_in_place' and 'runtime' are accepted; anything else produces this error naming the offending token.

Source

Thrown at linera-storage-runtime/src/storage_config.rs:162

                let namespace = DEFAULT_NAMESPACE.to_string();
                let spawn_mode = RocksDbSpawnMode::SpawnBlocking;
                let inner_storage_config = InnerStorageConfig::RocksDb { path, spawn_mode };
                return Ok(StorageConfig {
                    inner_storage_config,
                    namespace,
                });
            }
            if parts.len() == 2 || parts.len() == 3 {
                let path = parts[0].to_string().into();
                let spawn_mode_name = parts
                    .get(1)
                    .copied()
                    .expect("validated by the parts length check above");
                let spawn_mode = match spawn_mode_name {
                    "spawn_blocking" => Ok(RocksDbSpawnMode::SpawnBlocking),
                    "block_in_place" => Ok(RocksDbSpawnMode::BlockInPlace),
                    "runtime" => Ok(RocksDbSpawnMode::get_spawn_mode_from_runtime()),
                    _ => Err(anyhow!("Failed to parse {spawn_mode_name} as a spawn_mode")),
                }?;
                let namespace = if parts.len() == 2 {
                    DEFAULT_NAMESPACE.to_string()
                } else {
                    parts[2].to_string()
                };
                let inner_storage_config = InnerStorageConfig::RocksDb { path, spawn_mode };
                return Ok(StorageConfig {
                    inner_storage_config,
                    namespace,
                });
            }
            bail!("We should have one, two or three parts");
        }
        #[cfg(feature = "scylladb")]
        if let Some(s) = input.strip_prefix(SCYLLA_DB) {
            let mut uri: Option<String> = None;
            let mut namespace: Option<String> = None;

View on GitHub (pinned to 6c226ddcb3)

Solutions

  1. Use one of the three literal values: spawn_blocking, block_in_place, or runtime
  2. Re-check field order: rocksdb:<directory>:<spawn_mode> or rocksdb:<directory>:<spawn_mode>:<namespace>
  3. If you do not care about the mode, use the short form 'rocksdb:<directory>' which defaults to spawn_blocking

Example fix

# before
--storage rocksdb:/tmp/linera:blocking
# after
--storage rocksdb:/tmp/linera:block_in_place
Defensive patterns

Strategy: validation

Validate before calling

// Rust: validate spawn_mode before building the config string
fn is_valid_spawn_mode(s: &str) -> bool {
    matches!(s, "spawn_blocking" | "block_in_place" | "runtime")
}
if let Some(mode) = spawn_mode {
    anyhow::ensure!(is_valid_spawn_mode(mode), "spawn_mode must be spawn_blocking|block_in_place|runtime");
}

Type guard

fn is_valid_spawn_mode(s: &str) -> bool {
    matches!(s, "spawn_blocking" | "block_in_place" | "runtime")
}

Try / catch

match StorageConfig::from_str(&storage_str) {
    Ok(cfg) => cfg,
    Err(e) => {
        eprintln!("bad --storage {storage_str:?}: {e:#}");
        std::process::exit(2);
    }
}

Prevention

When it happens

Trigger: Configuring storage like 'rocksdb:/tmp/linera:spawn_blocking' is fine, but 'rocksdb:/tmp/linera:blocking', 'rocksdb:/tmp/linera:thread' or a misplaced field (e.g. passing the namespace in the spawn_mode slot) fails here. Raised from from_str(), typically while parsing the --storage CLI argument at startup.

Common situations: Guessing the enum value instead of checking the three literals; older tutorials naming modes differently; field-order confusion between directory, spawn mode and optional namespace.

Understand the failure class

Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.

Related errors


AI-assisted analysis of linera-io/linera-protocol@6c226ddcb3 (2026-08-22). Data as JSON: /api/errors/39c15ceb0868ea45. Report an issue: GitHub.