nautechsystems/nautilus_trader · error · anyhow::Error
Invalid spec pair: {kv}
Error message
Invalid spec pair: {kv} What it means
LoggingSpec::from_spec parses a comma-separated key=value spec string into a LoggingConfig. When a key is not one of the recognized flag keys (is_colored, print_config, use_tracing, bypass_logging, fileout_sync_on_flush, buffered_stdout, etc.) the parser aborts with this error. It means the spec string contains an unrecognized key or is malformed.
Source
Thrown at crates/common/src/logging/config.rs:224
let mut config = Self::default();
for kv in spec.split(';') {
let kv = kv.trim();
if kv.is_empty() {
continue;
}
let Some((k, v)) = kv.split_once('=') else {
// Handle bare flags (without =)
match kv.to_lowercase().as_str() {
"log_components_only" => config.log_components_only = true,
"is_colored" => config.is_colored = true,
"print_config" => config.print_config = true,
"use_tracing" => config.use_tracing = true,
"bypass_logging" => config.bypass_logging = true,
"fileout_sync_on_flush" => config.fileout_sync_on_flush = true,
"buffered_stdout" => config.buffered_stdout = true,
_ => anyhow::bail!("Invalid spec pair: {kv}"),
}
continue;
};
let k = k.trim();
let v = v.trim();
let k_lower = k.to_lowercase();
match k_lower.as_str() {
"is_colored" => {
config.is_colored = parse_bool_value(v);
}
"log_components_only" => {
config.log_components_only = parse_bool_value(v);
}
"print_config" => {
config.print_config = parse_bool_value(v);
}View on GitHub (pinned to 18893faf8b)
Solutions
- Check the spec string and correct the key spelling to one of the supported keys (is_colored, print_config, use_tracing, bypass_logging, fileout_sync_on_flush, buffered_stdout).
- Verify each pair is formatted `key=value` with no stray separators or whitespace-only tokens.
- Check the version of the crate you are using: some spec keys exist only in certain releases; consult the config module docs for that version.
- Remove options that are not supported and set them programmatically on LoggingConfig instead.
Example fix
// before
let config = LoggingSpec::from_spec("color=true,print_config")?;
// after
let config = LoggingSpec::from_spec("is_colored=true,print_config=true")?; Defensive patterns
Strategy: validation
Validate before calling
const VALID_KEYS: [&str; 6] = ["is_colored", "print_config", "use_tracing", "bypass_logging", "fileout_sync_on_flush", "buffered_stdout"];
fn spec_keys_valid(spec: &str) -> bool {
spec.split(',').all(|kv| {
let key = kv.split('=').next().unwrap_or("").trim();
VALID_KEYS.contains(&key)
});
} Try / catch
match LoggingSpec::from_spec(spec) {
Ok(cfg) => cfg,
Err(e) if e.to_string().contains("Invalid spec pair") => {
eprintln!("bad logging spec '{spec}': {e}");
LoggingSpec::default()
}
Err(e) => return Err(e),
} Prevention
- Keep spec strings centralized in one constant rather than scattered literals.
- Add a unit test that parses every documented spec key.
- Copy spec examples only from the docs of the exact crate version in use.
When it happens
Trigger: Calling from_spec (or the higher-level env/config parsing that delegates to it) with a spec pair whose key is not in the accepted set, e.g. `color=true` instead of `is_colored=true`, or a bare token like `verbose` without `=` that falls through to the flag/pair branches and fails.
Common situations: Typos in environment-variable-driven logging config (e.g. NAUTILUS_LOG spec strings), copying spec options from documentation of a different version where a key was renamed or removed, or accidentally passing free-form text as a spec.
Understand the failure class
Background: "Invalid value" and "allowed values are" config errors: what your library rejected and how to fix it — this error's family across 41 libraries.
Related errors
- Tracing subscriber already initialized
- Logging has been shut down and cannot be re-initialized
- Global logging sender was already published
- Logging is running without a published sender
- Failed to initialize tracing subscriber: {e}
AI-assisted analysis of nautechsystems/nautilus_trader@18893faf8b (2026-09-08).
Data as JSON: /api/errors/679d45a63e48efd8.
Report an issue: GitHub.