{"record":{"id":"2248bc1e12d85af7","repo":"libnyanpasu/clash-nyanpasu","slug":"uid-required-for-profile-editor","errorCode":null,"errorMessage":"uid required for Profile editor","messagePattern":"uid required for Profile editor","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"backend/tauri/src/utils/resolve.rs","lineNumber":734,"sourceCode":"        x: x as i32,\n        y: y as i32,\n    });\n    let _ = win.show();\n    let _ = win.set_focus();\n\n    Ok(())\n}\n\n/// Create editor window with window_type and optional uid\n#[tracing_attributes::instrument(skip(app_handle))]\npub fn create_editor_window(\n    app_handle: &AppHandle,\n    window_type: EditorWindowType,\n    uid: Option<&str>,\n) -> Result<()> {\n    let window = match &window_type {\n        EditorWindowType::Profile => {\n            let uid = uid.ok_or_else(|| anyhow::anyhow!(\"uid required for Profile editor\"))?;\n            EditorWindow::profile(uid)\n        }\n        EditorWindowType::CssEditor => EditorWindow::css_editor(),\n    };\n    let mut builder = WindowParamsBuilder::new().param(\"type\", window_type.type_str());\n    if let Some(u) = uid {\n        builder = builder.param(\"uid\", u);\n    }\n    window.create_with_params(app_handle, builder.build())?;\n    Ok(())\n}\n\n/// Close editor window by window_type and optional uid\n#[allow(dead_code)]\npub fn close_editor_window(\n    app_handle: &AppHandle,\n    window_type: &EditorWindowType,\n    uid: Option<&str>,","sourceCodeStart":716,"sourceCodeEnd":752,"githubUrl":"https://github.com/libnyanpasu/clash-nyanpasu/blob/f7dbce2997c633e484f54788035e770b3ee99773/backend/tauri/src/utils/resolve.rs#L716-L752","documentation":"create_editor_window builds an EditorWindow for either the Profile editor or the CSS editor. The Profile variant embeds the profile uid in the window URL/params, so a None uid is invalid there and the function raises this error before creating any window.","triggerScenarios":"Calling create_editor_window(app_handle, EditorWindowType::Profile, None) — or passing a uid only for other editor types — instead of supplying Some(\"<profile-uid>\").","commonSituations":"Callers generic over EditorWindowType defaulting uid to None; a UI action launched from a context that lost the selected profile id; refactors that made uid optional for all editor kinds.","solutions":["Pass Some(uid) with the profile's id when window_type is EditorWindowType::Profile","Make the caller resolve the selected profile before invoking the editor","If uid is genuinely absent, fall back to CssEditor or show a user-facing selection prompt instead","Consider splitting the API into create_profile_editor(uid) to make the parameter required"],"exampleFix":"// before\ncreate_editor_window(app, EditorWindowType::Profile, None).await?;\n// after\nlet uid = profiles.current().ok_or_else(|| anyhow!(\"no profile selected\"))?;\ncreate_editor_window(app, EditorWindowType::Profile, Some(uid.as_str())).await?;","handlingStrategy":"validation","validationCode":"if window_type == EditorWindowType::Profile && uid.is_none() {\n    return Err(anyhow!(\"Profile editor requires a uid\"));\n}","typeGuard":"fn uid_for(window_type: EditorWindowType, uid: Option<&str>) -> Result<&str> {\n    match window_type {\n        EditorWindowType::Profile => uid.ok_or_else(|| anyhow!(\"uid required for Profile editor\")),\n        EditorWindowType::CssEditor => Ok(uid.unwrap_or(\"\")),\n    }\n}","tryCatchPattern":"match create_editor_window(app, window_type, uid).await {\n    Err(e) if e.to_string().contains(\"uid required\") => {\n        // prompt user to select a profile first\n    }\n    other => other?,\n}","preventionTips":["Make uid a required parameter by splitting Profile into its own constructor","Resolve the current profile id before opening the editor","Keep EditorWindowType and its required args together in one struct"],"tags":["window","editor","validation","missing-argument"],"backgroundTag":"missing-required-argument","analyzedSha":"f7dbce2997c633e484f54788035e770b3ee99773","analyzedAt":"2026-09-08T01:24:59.197Z","contentChangedAt":"2026-09-08T01:24:59.197Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}