tonhowtf/omniget · error

ja esta gravando

Error message

ja esta gravando

What it means

screen_record::start() keeps the active recording in a global SESSION mutex. If a session is already present, starting another one raises this error ('already recording') — the tool supports only one screen recording at a time per process.

Solutions

  1. Call stop() before start() if a session may be active
  2. Check the current state via state() / the SESSION-based accessor before starting
  3. Fix callers that leak sessions on error paths — ensure stop() runs in a cleanup/finalizer
  4. If a stale session is certain (dead ffmpeg child), stop it first to release the slot

Example fix

// before
start(opts).await?; // may fail if already recording
// after
if state().recording { stop().await?; }
start(opts).await?;
Defensive patterns

Strategy: validation

Validate before calling

if screen_record::state().recording {
    return Err(anyhow!("a recording is already active"));
}

Try / catch

match screen_record::start(opts).await {
    Ok(s) => Ok(s),
    Err(e) if e.to_string().contains("ja esta gravando") => {
        // stop the previous session, then retry once
        screen_record::stop().await?;
        screen_record::start(opts).await
    }
    Err(e) => Err(e),
}

Prevention

When it happens

Trigger: Calling start() twice without an intervening stop(); a previous session that was never stopped because its process is long-lived; calling start from two concurrent invocations.

Common situations: A UI button double-click launching two recordings; a crash of the calling layer leaving the session registered; an automation script that starts recording each run but only stops on success paths.

Understand the failure class

Background: "Invalid state transition" errors: "status must be X, actually Y", "already rejected/charging/uninstalled", "cannot ... while running" — what they mean when a library rejects your call — this error's family across 31 libraries.

Related errors


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

Appendix: source

Thrown at src-tauri/omniget-core/src/core/tools/screen_record.rs:334

            "-segment_time".into(),
            "5".into(),
            "-segment_wrap".into(),
            wrap,
            "-reset_timestamps".into(),
            "1".into(),
            "-segment_format_options".into(),
            "movflags=+faststart".into(),
        ]);
        a.push(target.join("seg-%03d.mp4").to_string_lossy().to_string());
    } else {
        a.push(target.to_string_lossy().to_string());
    }
    a
}

pub async fn start(opts: RecordOptions) -> anyhow::Result<RecordState> {
    if SESSION.lock().unwrap_or_else(|e| e.into_inner()).is_some() {
        return Err(anyhow!("ja esta gravando"));
    }
    if cfg!(target_os = "linux")
        && std::env::var("WAYLAND_DISPLAY").is_ok()
        && std::env::var("DISPLAY").is_err()
    {
        return Err(anyhow!("sessao Wayland sem XWayland: o x11grab nao enxerga a tela. Use a captura do OmniDisc (PipeWire) ou entre numa sessao X11."));
    }
    let ffmpeg = crate::core::dependencies::ensure_ffmpeg().await?;
    let dir = if opts.output_dir.trim().is_empty() {
        videos_dir()
    } else {
        PathBuf::from(opts.output_dir.trim())
    };
    std::fs::create_dir_all(&dir)?;
    let ring = opts.replay_seconds > 0;
    let (target, ring_dir, output) = if ring {
        let r = super::temp_dir().join(format!("replay-{}", uuid::Uuid::new_v4()));
        std::fs::create_dir_all(&r)?;

View on GitHub (pinned to 8600b91f42)