nautechsystems/nautilus_trader · error

Gamma {scope} filter '{key}' cannot be empty

Error message

Gamma {scope} filter '{key}' cannot be empty

What it means

Generic guard in the Polymarket Gamma API filter parser: a filter value that must be a non-empty string was blank or whitespace-only, so the Gamma request would be built with an empty filter clause and is rejected instead.

Source

Thrown at crates/adapters/polymarket/src/providers.rs:1028

    scope: &str,
    key: &str,
    value: &str,
) -> anyhow::Result<Vec<u64>> {
    parse_gamma_filter_list(scope, key, value)?
        .into_iter()
        .map(|item| {
            item.parse::<u64>().map_err(|e| {
                anyhow::anyhow!(
                    "Gamma {scope} filter '{key}' values must be unsigned integers: {e}"
                )
            })
        })
        .collect()
}

fn parse_gamma_filter_string(scope: &str, key: &str, value: &str) -> anyhow::Result<String> {
    if value.trim().is_empty() {
        anyhow::bail!("Gamma {scope} filter '{key}' cannot be empty")
    }
    Ok(value.to_string())
}

/// Resolves a tag slug to a tag ID by querying the Gamma tags endpoint.
pub async fn resolve_tag_slug(
    client: &PolymarketGammaHttpClient,
    slug: &str,
) -> anyhow::Result<u64> {
    let tags = client.request_tags().await?;
    let tag_id = tags
        .iter()
        .find(|t| t.slug.as_deref() == Some(slug))
        .map(|t| t.id.as_str())
        .ok_or_else(|| anyhow::anyhow!("Tag slug '{slug}' not found"))?;
    tag_id
        .parse::<u64>()
        .map_err(|e| anyhow::anyhow!("Tag slug '{slug}' returned invalid ID '{tag_id}': {e}"))

View on GitHub (pinned to 18893faf8b)

Solutions

  1. Omit the key from the filter map when the value is empty
  2. Trim and validate the value in the caller before inserting it
  3. Use Option<String> in config and only add the filter when Some and non-empty

Example fix

// before
filters.insert("slug".into(), cfg.slug.clone()); // may be ""
// after
if !cfg.slug.trim().is_empty() {
    filters.insert("slug".into(), cfg.slug.clone());
}
Defensive patterns

Strategy: validation

Validate before calling

fn add_string_filter(filters: &mut HashMap<String,String>, key: &str, v: &str) {
    if !v.trim().is_empty() {
        filters.insert(key.to_string(), v.to_string());
    }
}

Type guard

fn is_non_blank(v: &str) -> bool { !v.trim().is_empty() }

Prevention

When it happens

Trigger: Passing '' or ' ' for a string filter key (e.g. slug, locale) in build_gamma_params_from_hashmap via query_markets or the instrument loaders.

Common situations: Optional config values left empty; env vars set but blank; string defaults of '' used as placeholders then passed through unconditionally.

Understand the failure class

Background: "must not be empty", "cannot be empty" — required-field validation errors across open-source libraries — this error's family across 41 libraries.

Related errors


AI-assisted analysis of nautechsystems/nautilus_trader@18893faf8b (2026-09-08). Data as JSON: /api/errors/ef9c754ef0de33b2. Report an issue: GitHub.