tonhowtf/omniget · error

a saída do gallery-dl não é um dump JSON válido

Error message

a saída do gallery-dl não é um dump JSON válido

What it means

parse_dump parses gallery-dl JSON output and collects Entry objects; if no entry could be extracted from any top-level JSON value, it concludes the output is not a valid gallery-dl JSON dump and throws. This guards downstream code against operating on an empty or structurally unexpected document.

Solutions

  1. Run gallery-dl -j <url> manually and inspect the raw output shape
  2. Update or pin gallery-dl to a version whose JSON dump matches the expected schema
  3. Check gallery-dl's stderr/exit status upstream so error payloads are not fed to parse_dump
  4. Confirm the URL has media (gallery not empty) before parsing

Example fix

// before
let text = stdout;
let entries = parse_dump(&text)?;
// after
let text = stdout;
if !status.success() || text.trim().is_empty() {
    anyhow::bail!("gallery-dl falhou: {}", stderr_tail);
}
let entries = parse_dump(&text)?;
Defensive patterns

Strategy: try-catch

Validate before calling

let parsed: Result<serde_json::Value, _> = serde_json::from_str(&text);
if parsed.map_or(true, |v| v.as_array().map_or(true, |a| a.is_empty())) {
    anyhow::bail!("gallery-dl não retornou entradas; verifique URL/cookies antes de parse_dump");
}

Type guard

fn is_valid_dump(v: &serde_json::Value) -> bool {
    v.as_array().map_or(false, |a| !a.is_empty())
}

Try / catch

match parse_dump(&text) {
    Ok(entries) => entries,
    Err(e) if e.to_string().contains("não é um dump JSON válido") => {
        eprintln!("stdout bruto: {}", &text[..text.len().min(500)]);
        return Err(e);
    }
    Err(e) => return Err(e),
}

Prevention

When it happens

Trigger: gallery-dl -j returned JSON that is not an array of arrays/objects in the expected shape, or the command emitted valid JSON but with zero recognizable entries (e.g. an error object, null, or an empty array).

Common situations: gallery-dl version changed its JSON schema; URL is a page with no media so output is [] or an error JSON; gallery-dl printed a warning object instead of a dump; cookies are stale so the extractor returns an auth error payload.

Related errors


AI-assisted analysis of tonhowtf/omniget@8600b91f42 (2026-09-12). Data as JSON: /api/errors/9a3f0099f6211c03. Report an issue: GitHub.

Appendix: source

Thrown at src-tauri/omniget-core/src/core/tools/tumblr/gdl.rs:120

        return Ok(Vec::new());
    }
    if let Ok(Value::Array(items)) = serde_json::from_str::<Value>(trimmed) {
        return Ok(items.iter().filter_map(entry_from).collect());
    }
    let mut out = Vec::new();
    for line in trimmed.lines() {
        let line = line.trim().trim_end_matches(',');
        if line.is_empty() || line == "[" || line == "]" {
            continue;
        }
        if let Ok(v) = serde_json::from_str::<Value>(line) {
            if let Some(e) = entry_from(&v) {
                out.push(e);
            }
        }
    }
    if out.is_empty() {
        return Err(anyhow!("a saída do gallery-dl não é um dump JSON válido"));
    }
    Ok(out)
}

fn entry_from(value: &Value) -> Option<Entry> {
    let items = value.as_array()?;
    let kind = items.first()?.as_u64()?;
    match items.len() {
        2 => Some(Entry {
            kind,
            url: None,
            meta: items[1].clone(),
        }),
        3.. => Some(Entry {
            kind,
            url: items[1].as_str().map(|s| s.to_string()),
            meta: items[2].clone(),
        }),

View on GitHub (pinned to 8600b91f42)