{"record":{"id":"9a30583a47524b77","repo":"libnyanpasu/clash-nyanpasu","slug":"prepare-called-more-than-once-with-different-ide-9a3058","errorCode":null,"errorMessage":"prepare() called more than once with different identifiers.","messagePattern":"prepare\\(\\) called more than once with different identifiers\\.","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"backend/tauri-plugin-deep-link/src/windows.rs","lineNumber":202,"sourceCode":"                        let pid = buf.parse::<u32>().unwrap_or(ASFW_ANY);\n                        unsafe {\n                            let success = AllowSetForegroundWindow(pid) != 0;\n                            if !success {\n                                eprintln!(\"AllowSetForegroundWindow failed.\");\n                            }\n                        }\n                        std::process::exit(0);\n                    }\n                    Err(e) => {\n                        eprintln!(\"Failed to connect to local socket: {e}\");\n                        std::thread::sleep(std::time::Duration::from_millis(1));\n                    }\n                };\n            }\n        });\n\n    ID.set(identifier.to_string())\n        .expect(\"prepare() called more than once with different identifiers.\");\n}\n\n/// Send a dummy keypress event so AllowSetForegroundWindow can succeed\nfn dummy_keypress() {\n    let keyboard_input_down = KEYBDINPUT {\n        wVk: 0, // This doesn't correspond to any actual keyboard key, but should still function for the workaround.\n        dwExtraInfo: 0,\n        wScan: 0,\n        time: 0,\n        dwFlags: 0,\n    };\n\n    let mut keyboard_input_up = keyboard_input_down;\n    keyboard_input_up.dwFlags = 0x0002; // KEYUP flag\n\n    let input_down_u = INPUT_0 {\n        ki: keyboard_input_down,\n    };","sourceCodeStart":184,"sourceCodeEnd":220,"githubUrl":"https://github.com/libnyanpasu/clash-nyanpasu/blob/f7dbce2997c633e484f54788035e770b3ee99773/backend/tauri-plugin-deep-link/src/windows.rs#L184-L220","documentation":"The deep-link plugin stores the app identifier once via OnceCell (ID.set). If prepare() is invoked a second time with a different identifier string, set() returns Err and the .expect panics. This guards the invariant that one process has exactly one deep-link identifier for the Windows foreground-window workaround.","triggerScenarios":"Calling plugin prepare()/deep_link APIs twice during startup with differing identifier values — typically registering the deep-link plugin twice, or re-invoking prepare after config reload changed the identifier.","commonSituations":"Accidentally adding the deep-link plugin (or a plugin depending on it) twice to the Tauri builder; dynamic identifier derived from config that differs across initialization passes; test harnesses rebuilding the app builder per test with different identifiers in one process.","solutions":["Call prepare() only once per process with a constant identifier string","Verify the plugin isn't registered twice in the Tauri builder chain","Make the identifier a compile-time constant (e.g. from tauri.conf.json identifier) rather than a computed value","In tests, run each identifier in a separate process or reset state between runs"],"exampleFix":"// before\nprepare(config.identifier.clone() + \"-v2\");\n// after\nprepare(env!(\"CARGO_PKG_NAME\").to_string()); // stable, same value every call","handlingStrategy":"validation","validationCode":"static INITIALIZED: AtomicBool = AtomicBool::new(false);\nassert!(!INITIALIZED.swap(true, Ordering::SeqCst), \"prepare() already called\");","typeGuard":null,"tryCatchPattern":"if ID.set(identifier.to_string()).is_err() {\n    eprintln!(\"prepare() called twice with different identifiers\");\n}","preventionTips":["Register the deep-link plugin exactly once in the Tauri builder","Derive the identifier from a single constant source (tauri.conf.json)"],"tags":["windows","initialization","panic","duplicate-init"],"backgroundTag":"internal-invariant-violation","analyzedSha":"f7dbce2997c633e484f54788035e770b3ee99773","analyzedAt":"2026-09-08T01:24:59.197Z","contentChangedAt":"2026-09-08T01:24:59.197Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}