{"record":{"id":"cde8315803a58dcd","repo":"linebender/druid","slug":"more-than-one-path-received-for-single-selection","errorCode":null,"errorMessage":"More than one path received for single selection","messagePattern":"More than one path received for single selection","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"druid-shell/src/backend/gtk/dialog.rs","lineNumber":93,"sourceCode":"        if let Some(dt) = &options.default_type {\n            if !found_default_filter {\n                tracing::warn!(\"The default type {:?} is not present in allowed types.\", dt);\n            }\n        }\n    }\n\n    if let Some(default_name) = &options.default_name {\n        dialog.set_current_name(default_name);\n    }\n\n    let result = dialog.run();\n\n    let result = match result {\n        ResponseType::Accept => match dialog.filenames() {\n            filenames if filenames.is_empty() => Err(anyhow!(\"No path received for filename\")),\n            // If we receive more than one file, but `multi_selection` is false, return an error.\n            filenames if filenames.len() > 1 && !options.multi_selection => {\n                Err(anyhow!(\"More than one path received for single selection\"))\n            }\n            // If we receive more than one file with a save action, return an error.\n            filenames if filenames.len() > 1 && action == FileChooserAction::Save => {\n                Err(anyhow!(\"More than one path received for save action\"))\n            }\n            filenames => Ok(filenames.into_iter().map(|p| p.into_os_string()).collect()),\n        },\n        ResponseType::Cancel => Err(anyhow!(\"Dialog was deleted\")),\n        _ => {\n            tracing::warn!(\"Unhandled dialog result: {:?}\", result);\n            Err(anyhow!(\"Unhandled dialog result\"))\n        }\n    };\n\n    // TODO properly handle errors into the Error type\n\n    dialog.destroy();\n","sourceCodeStart":75,"sourceCodeEnd":111,"githubUrl":"https://github.com/linebender/druid/blob/0f8b1195e4e073f9597f2865299c3d18f8e4005f/druid-shell/src/backend/gtk/dialog.rs#L75-L111","documentation":"druid-shell's GTK file dialog can return multiple filenames when multi-selection is enabled in the native chooser. If the dialog was opened with `multi_selection: false` but the chooser still returns more than one file, the API contract (exactly one path for single selection) is broken, so an anyhow error is returned.","triggerScenarios":"Calling FileDialog with multi_selection disabled while the underlying GTK FileChooser is in a state allowing multiple selection (mismatch between druid's `FileDialogOptions` and the constructed chooser widget), then the user selects several files and accepts.","commonSituations":"Configuring options after the dialog was created or ignoring `multi_selection` when constructing the GTK chooser; user selecting multiple files (Ctrl/Shift-click) in a dialog that should be single-select; version drift where the options flag stopped being honored.","solutions":["Ensure `FileDialogOptions.multi_selection` is correctly propagated when constructing the GTK FileChooser (select_folder/select_file vs select-multiple action)","Druid (>=0.7/0.8) restricts FileDialog usage to directory selection only — prefer `FileDialog::open_directory` and update code that expects file multi-selection","Handle the returned Result gracefully (treat like cancellation) and/or filter to the first file if your app can tolerate it"],"exampleFix":"// before\nlet paths: Vec<PathBuf> = dialog.get_paths().unwrap(); // assumes exactly one\n// after\nmatch get_file_dialog_path(...) {\n    Ok(mut paths) if paths.len() == 1 => use(paths.remove(0)),\n    _ => { /* cancelled or invalid selection */ }\n}","handlingStrategy":"validation","validationCode":"// Validate options and results before use\nassert_eq!(options.multi_selection, false);\nmatch paths.len() {\n    1 => use_path(paths[0].clone()),\n    _ => cancel(),\n}","typeGuard":null,"tryCatchPattern":"match result { Err(e) if e.to_string().contains(\"More than one path\") => { /* fall back to first path or cancel */ }, other => other }","preventionTips":["Keep multi_selection option and the GTK chooser mode in sync","Restrict selection count downstream even when the option is honored","Prefer druid's open_directory API where multi-selection is unsupported"],"tags":["druid-shell","gtk","file-dialog","multi-selection","options-mismatch","rust"],"backgroundTag":"conflicting-config-options","analyzedSha":"0f8b1195e4e073f9597f2865299c3d18f8e4005f","analyzedAt":"2026-09-10T14:27:34.582Z","contentChangedAt":"2026-09-10T14:27:34.582Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}