{"record":{"id":"984d604030cc9d61","repo":"tonhowtf/omniget","slug":"o-replay-nao-esta-ligado","errorCode":null,"errorMessage":"o replay nao esta ligado","messagePattern":"o replay nao esta ligado","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src-tauri/omniget-core/src/core/tools/screen_record.rs","lineNumber":440,"sourceCode":"    };\n    stop_child(sess.child).await;\n    if let Some(out) = &sess.output {\n        *LAST_SAVED.lock().unwrap_or_else(|e| e.into_inner()) =\n            Some(out.to_string_lossy().to_string());\n    }\n    if let Some(r) = &sess.ring_dir {\n        let _ = std::fs::remove_dir_all(r);\n    }\n    Ok(state())\n}\n\n/// Replay: junta os últimos segmentos num arquivo na pasta de saída, sem\n/// interromper a gravação do anel.\npub async fn save_replay() -> anyhow::Result<String> {\n    let (ring, opts) = {\n        let s = SESSION.lock().unwrap_or_else(|e| e.into_inner());\n        let Some(sess) = s.as_ref() else {\n            return Err(anyhow!(\"o replay nao esta ligado\"));\n        };\n        let Some(r) = sess.ring_dir.clone() else {\n            return Err(anyhow!(\"a gravacao atual nao e um replay\"));\n        };\n        (r, sess.opts.clone())\n    };\n    let ffmpeg = crate::core::dependencies::ensure_ffmpeg().await?;\n    let mut segs: Vec<(std::time::SystemTime, PathBuf)> = std::fs::read_dir(&ring)?\n        .flatten()\n        .filter_map(|e| {\n            let p = e.path();\n            let m = e.metadata().ok()?;\n            if p.extension().map(|x| x == \"mp4\").unwrap_or(false) && m.len() > 0 {\n                Some((m.modified().ok()?, p))\n            } else {\n                None\n            }\n        })","sourceCodeStart":422,"sourceCodeEnd":458,"githubUrl":"https://github.com/tonhowtf/omniget/blob/8600b91f4246848bac346874daa9e61c1fc5677a/src-tauri/omniget-core/src/core/tools/screen_record.rs#L422-L458","documentation":"save_replay stitches the last N ring-buffer segments into a replay file, but this only works while a screen recording session is active. If the SESSION mutex holds no session (recording was never started or already stopped), the function fails immediately with 'o replay nao esta ligado' (replay is not on). It is a guard against calling replay-only APIs outside an active recording.","triggerScenarios":"Calling the public save_replay() async function when SESSION.lock() returns None — i.e. no start of recording has happened in this process, or the session was already torn down by a stop call.","commonSituations":"Frontend invokes the replay command before the user pressed record; recording stopped asynchronously (crash/cleanup) but the UI still allows the replay button; a stale window/process calls replay after a restart of the backend.","solutions":["Start a recording session (with replay enabled) before calling save_replay.","Check session state in the UI and disable the replay action when not recording.","If recording should still be active, check whether stop/cleanup was called earlier or the process restarted and re-record."],"exampleFix":"// before\nlet out = save_replay().await?;\n// after\nif !is_recording() {\n    anyhow::bail!(\"inicie a gravacao antes de salvar o replay\");\n}\nlet out = save_replay().await?;","handlingStrategy":"try-catch","validationCode":"// Rust\nfn replay_available() -> bool {\n    SESSION.lock().unwrap_or_else(|e| e.into_inner())\n        .as_ref().map(|s| s.ring_dir.is_some()).unwrap_or(false)\n}","typeGuard":"fn has_active_replay_session(s: &Option<Session>) -> bool {\n    s.as_ref().map(|s| s.ring_dir.is_some()).unwrap_or(false)\n}","tryCatchPattern":"match save_replay().await {\n    Ok(path) => println!(\"replay salvo: {path}\"),\n    Err(e) if e.to_string().contains(\"replay nao esta ligado\") => {\n        eprintln!(\"inicie uma gravacao com replay antes de salvar\");\n    }\n    Err(e) => return Err(e),\n}","preventionTips":["Track recording state in the UI and disable replay actions when idle","Check session liveness before any replay call","Handle process restarts by resetting UI action availability"],"tags":["replay","session-state","rust","screen-recording"],"backgroundTag":"invalid-state-transition","analyzedSha":"8600b91f4246848bac346874daa9e61c1fc5677a","analyzedAt":"2026-09-12T14:29:19.317Z","contentChangedAt":"2026-09-12T14:29:19.317Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}