{"record":{"id":"964d7f77764d3977","repo":"tonhowtf/omniget","slug":"cps-fora-de-0-1-a-1000","errorCode":null,"errorMessage":"CPS fora de 0,1 a 1000","messagePattern":"CPS fora de 0,1 a 1000","errorType":"validation","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"src-tauri/omniget-core/src/core/tools/autoclick.rs","lineNumber":107,"sourceCode":"        }\n    }\n}\n\nfn button_of(name: &str) -> Button {\n    match name {\n        \"right\" => Button::Right,\n        \"middle\" => Button::Middle,\n        _ => Button::Left,\n    }\n}\n\npub fn start(opts: ClickOptions) -> anyhow::Result<()> {\n    if RUNNING.swap(true, Ordering::SeqCst) {\n        return Err(anyhow!(\"ja esta rodando\"));\n    }\n    if !(0.1..=1000.0).contains(&opts.cps) {\n        RUNNING.store(false, Ordering::SeqCst);\n        return Err(anyhow!(\"CPS fora de 0,1 a 1000\"));\n    }\n    *LAST_OPTS.lock().unwrap_or_else(|e| e.into_inner()) = Some(opts.clone());\n    *ERROR.lock().unwrap_or_else(|e| e.into_inner()) = None;\n    CLICKS.store(0, Ordering::SeqCst);\n    *STARTED.lock().unwrap_or_else(|e| e.into_inner()) = Some(Instant::now());\n\n    std::thread::Builder::new()\n        .name(\"omniget-autoclick\".into())\n        .spawn(move || {\n            let mut enigo = match Enigo::new(&Settings::default()) {\n                Ok(e) => e,\n                Err(e) => {\n                    *ERROR.lock().unwrap_or_else(|e| e.into_inner()) = Some(format!(\"nao consegui controlar o mouse: {} (macOS: Ajustes → Privacidade → Acessibilidade)\", e));\n                    RUNNING.store(false, Ordering::SeqCst);\n                    return;\n                }\n            };\n            if opts.start_delay > 0 {","sourceCodeStart":89,"sourceCodeEnd":125,"githubUrl":"https://github.com/tonhowtf/omniget/blob/8600b91f4246848bac346874daa9e61c1fc5677a/src-tauri/omniget-core/src/core/tools/autoclick.rs#L89-L125","documentation":"start() validates the requested clicks-per-second against the supported range 0.1..=1000.0 and rejects values outside it, resetting RUNNING to false first. The autoclicker's timing loop cannot honor intervals outside this window, so out-of-range CPS is rejected up front.","triggerScenarios":"Calling start() (or toggle() after configuring) with ClickOptions.cps < 0.1 (e.g. 0 or 0.05) or > 1000 (e.g. 5000), typically from deserialized UI/settings input that bypasses field validation.","commonSituations":"Manually editing a saved config file with cps: 0; typing a typo like 10000 in a settings field; importing settings from another tool with different limits; negative values from a buggy slider.","solutions":["Clamp cps into 0.1..=1000.0 before calling start(), e.g. opts.cps = opts.cps.clamp(0.1, 1000.0).","Validate the CPS input in the UI (slider/spinner bounds) so out-of-range values never reach start().","If the saved config may hold bad values, sanitize on load: map cps <= 0 or absurdly high values to sane defaults.","Show the allowed range in the UI error/help text so users understand the limit."],"exampleFix":"// before\nlet opts = ClickOptions { cps: 5000.0, ..read_config()? };\nstart(opts)?; // Err: CPS fora de 0,1 a 1000\n// after\nlet mut opts = read_config()?;\nopts.cps = opts.cps.clamp(0.1, 1000.0);\nstart(opts)?;","handlingStrategy":"validation","validationCode":"fn valid_cps(cps: f64) -> bool { (0.1..=1000.0).contains(&cps) && cps.is_finite() }","typeGuard":"fn sanitize_click_options(mut o: ClickOptions) -> ClickOptions {\n    if !o.cps.is_finite() { o.cps = 10.0; }\n    o.cps = o.cps.clamp(0.1, 1000.0);\n    o\n}","tryCatchPattern":"match autoclick::start(opts) {\n    Err(e) if e.to_string().contains(\"CPS fora\") =>\n        show_hint(\"Use CPS entre 0,1 e 1000\"),\n    other => other?,\n}","preventionTips":["Bound the CPS input widget to 0.1–1000 in the UI.","Clamp cps when loading saved/imported configs.","Reject non-finite (NaN/inf) values at deserialization time.","Document the allowed range next to the setting."],"tags":["rust","autoclicker","validation","range-check"],"backgroundTag":"value-out-of-range","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"}