slint-ui/slint · warning
Failed to create a Slint file in
Error message
Failed to create a Slint file in {}: {error} What it means
The editor preview's file-tree 'create new Slint file' action failed. The plugin resolved a create-controller for the project root and asked it to create a new .slint file; the underlying create operation returned an Err, which is logged as a warning with the project root path. The UI does not surface a hard error - it degrades to a logged warning.
Solutions
- Check the logged error detail and verify the directory controller.root.display() exists and is writable
- Ensure the intended file name is valid and does not already exist
- Rebuild/refresh the project controller so it points at the actual project root
- Create the file manually in the IDE and reload the preview
Example fix
// before
return Default::default();
// after
// surface the failure instead of swallowing it
match controller.create_new_slint_file(&project) {
Ok(path) => /* update tree with path */,
Err(error) => show_error_notification(&format!("Failed to create file: {error}")),
} Defensive patterns
Strategy: validation
Validate before calling
if (!controller.root.as_path().is_dir()) { eprintln!("project root missing: {}", controller.root.display()); return; }
if std::fs::metadata(&controller.root).map(|m| m.permissions().readonly()).unwrap_or(true) { eprintln!("project root read-only"); return; } Type guard
fn is_writable_dir(p: &std::path::Path) -> bool {
std::fs::metadata(p).map(|m| m.is_dir() && !m.permissions().readonly()).unwrap_or(false)
} Try / catch
match controller.create_new_slint_file(&project) {
Ok(path) => refresh_tree(&path),
Err(e) => notify_user(&format!("Create failed: {e}")),
} Prevention
- Validate the project root exists and is writable before enabling the create action
- Check for name collisions before creating a file
- Refresh the project controller when the workspace root changes
When it happens
Trigger: Calling the create-new-file handler when controller.create_new_slint_file(&project) fails, e.g. the target directory is not writable, the file already exists, or the project path is invalid.
Common situations: User tries to create a new .slint file from the IDE preview's file tree in a read-only directory, a path with invalid characters, or when the project root moved/deleted after the controller was built.
Understand the failure class
Background: "failed to write file", "Could not save figure", "Error saving remote file" — file write failed: causes and fixes across languages and libraries — this error's family across 38 libraries.
Related errors
- a setter belongs to a field
- an identifier
- attempt to multiply with overflow
- binding was of the wrong type
- Called a not-implemented method
AI-assisted analysis of slint-ui/slint@3a7e700487 (2026-09-16).
Data as JSON: /api/errors/16a4f8e849d7e02b.
Report an issue: GitHub.
Appendix: source
Thrown at tools/editor/preview/ui/file_tree.rs:44
project: &Project<'_>,
project_weak: slint::Weak<Project<'static>>,
) -> SharedFileTreeController {
project.set_file_tree(Default::default());
project.set_selected_project_file(Default::default());
let controller: SharedFileTreeController = Rc::new(RefCell::new(None));
let controller_for_create = controller.clone();
let project_weak_for_create = project_weak.clone();
project.on_create_new_slint_file(move || {
let Some(project) = project_weak_for_create.upgrade() else {
return Default::default();
};
let mut controller = controller_for_create.borrow_mut();
let Some(controller) = controller.as_mut() else {
return Default::default();
};
controller.create_new_slint_file(&project).err().map_or_else(
SharedString::default,
|error| {
tracing::warn!(
"Failed to create a Slint file in {}: {error}",
controller.root.display()
);
error.to_shared_string()
},
)
});
let controller_for_select = controller.clone();
let api_weak_for_select = api_weak.clone();
let project_weak_for_select = project_weak.clone();
api.on_file_tree_select(move |path| {
if let Some(api) = api_weak_for_select.upgrade()
&& let Some(project) = project_weak_for_select.upgrade()
&& let Some(controller) = controller_for_select.borrow_mut().as_mut()View on GitHub (pinned to 3a7e700487)