LykosAI/StabilityMatrix · warning · DataValidationException
File name already exists
Error message
File name already exists
What it means
In CheckpointFileViewModel.RenameAsync, the dialog Validator throws DataValidationException("File name already exists") when File.Exists confirms that parentPath + the entered name collides with an existing file. The rename is blocked to avoid overwriting another checkpoint file.
Solutions
- Choose a unique file name that does not match any file in the target folder
- If overwriting is intended, delete the existing file first, then rename
- Add extension-aware or case-insensitive collision checking in the Validator if the current File.Exists check misses variants
Example fix
// before
if (File.Exists(Path.Combine(parentPath, text)))
throw new DataValidationException("File name already exists");
// after
var candidate = Directory.EnumerateFiles(parentPath)
.FirstOrDefault(f => string.Equals(Path.GetFileName(f), text, StringComparison.OrdinalIgnoreCase));
if (candidate is not null)
throw new DataValidationException($"File name already exists: {Path.GetFileName(candidate)}"); Defensive patterns
Strategy: validation
Validate before calling
// Validate before confirming the rename
var target = Path.Combine(parentPath, newName);
if (File.Exists(target))
throw new DataValidationException("File name already exists"); Type guard
bool IsFreeFileName(string parent, string name) =>
!string.IsNullOrWhiteSpace(name) &&
!Directory.EnumerateFiles(parent)
.Any(f => string.Equals(Path.GetFileName(f), name, StringComparison.OrdinalIgnoreCase)); Try / catch
try
{
await checkpointFileVm.RenameAsync();
}
catch (DataValidationException ex) when (ex.Message == "File name already exists")
{
Logger.Debug("Rename aborted: target file already exists");
// surface 'choose another name' in UI
} Prevention
- Check the target folder for existing files (case-insensitively on Windows) before renaming
- Avoid renaming copies back to the original checkpoint's name
- Consider auto-suffixing duplicates (e.g. name (1).safetensors) instead of failing
- Remember case-only renames collide on NTFS/APFS default settings
When it happens
Trigger: Submitting the 'Rename Model' dialog with a name that matches an existing file in the same checkpoint folder (exact name, or same name ignoring case on case-insensitive filesystems).
Common situations: Renaming a model to a name another checkpoint already uses; duplicating a checkpoint then renaming the copy back to the original name; case-only renames on Windows/NTFS.
Understand the failure class
Background: "already exists" / EEXIST / FileAlreadyExistsException: what the 'file already exists' error means and how to fix it — this error's family across 37 libraries.
Related errors
- File name is required
- Resources.Validation_PackageNameCannotBeEmpty
- string.Format(Resources.ValidationError_PackageExists, text)
- Length cannot be null when latentType is Hunyuan
- Invalid Token
AI-assisted analysis of LykosAI/StabilityMatrix@af93d6ef57 (2026-09-12).
Data as JSON: /api/errors/cb86ec8eb4b0d82b.
Report an issue: GitHub.
Appendix: source
Thrown at StabilityMatrix.Avalonia/ViewModels/CheckpointManager/CheckpointFileViewModel.cs:353
[RelayCommand]
private async Task RenameAsync()
{
// Parent folder path
var parentPath =
Path.GetDirectoryName((string?)CheckpointFile.GetFullPath(settingsManager.ModelsDirectory)) ?? "";
var textFields = new TextBoxField[]
{
new()
{
Label = "File name",
Validator = text =>
{
if (string.IsNullOrWhiteSpace(text))
throw new DataValidationException("File name is required");
if (File.Exists(Path.Combine(parentPath, text)))
throw new DataValidationException("File name already exists");
},
Text = CheckpointFile.FileName,
},
};
var dialog = DialogHelper.CreateTextEntryDialog("Rename Model", "", textFields);
if (await dialog.ShowAsync() == ContentDialogResult.Primary)
{
var name = textFields[0].Text;
var nameNoExt = Path.GetFileNameWithoutExtension(name);
var originalNameNoExt = Path.GetFileNameWithoutExtension(CheckpointFile.FileName);
// Rename file in OS
try
{
var newFilePath = Path.Combine(parentPath, name);
File.Move(CheckpointFile.GetFullPath(settingsManager.ModelsDirectory), newFilePath);
View on GitHub (pinned to af93d6ef57)