LykosAI/StabilityMatrix · error · DataValidationException

string.Format(Resources.ValidationError_PackageExists, text)

Error message

string.Format(Resources.ValidationError_PackageExists, text)

What it means

PackageCardViewModel validates a new package name before renaming/moving a package. After confirming the name is non-empty, it builds the target directory path from the package's current location and throws DataValidationException when a directory with that name already exists, preventing an ambiguous or destructive move.

Solutions

  1. Pick a different package name that does not exist in the package install directory.
  2. Delete or rename the conflicting folder on disk if it is a leftover from a failed operation.
  3. Check for case-only differences if on a case-insensitive filesystem (Windows/macOS).

Example fix

// before
throw new DataValidationException(string.Format(Resources.ValidationError_PackageExists, text));
// after
var directoryPath = new DirectoryPath(Path.GetDirectoryName(Package.FullPath!)!, text);
if (directoryPath.Exists)
{
    text = text + "-1"; // auto-suffix or prompt user for a new name
}
Defensive patterns

Strategy: validation

Validate before calling

var target = new DirectoryPath(Path.GetDirectoryName(package.FullPath!)!, newName);
if (string.IsNullOrWhiteSpace(newName) || target.Exists)
    return; // block rename or prompt for another name

Try / catch

try { await DoRenameAsync(text); }
catch (DataValidationException ex) { ShowDialog("Cannot rename", ex.Message); }

Prevention

When it happens

Trigger: Calling the rename validation (in PackageCardViewModel, e.g. via the rename dialog's validator at StabilityMatrix.Avalonia/ViewModels/PackageManager/PackageCardViewModel.cs:896) with a text value whose corresponding directory `Path.GetDirectoryName(Package.FullPath)/text` already exists on disk.

Common situations: Renaming a package to a name that another package (or leftover folder from a failed install/uninstall) already uses; case-insensitive filesystems where 'MyPack' collides with 'mypack'; stale package folders not cleaned up after a crash.

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


AI-assisted analysis of LykosAI/StabilityMatrix@af93d6ef57 (2026-09-12). Data as JSON: /api/errors/c3440359df43d69d. Report an issue: GitHub.

Appendix: source

Thrown at StabilityMatrix.Avalonia/ViewModels/PackageManager/PackageCardViewModel.cs:896

            return;

        var currentName = Package.DisplayName ?? Package.PackageName ?? string.Empty;
        var field = new TextBoxField
        {
            Label = Resources.Label_DisplayName,
            Text = currentName,
            Watermark = Resources.Watermark_EnterPackageName,
            Validator = text =>
            {
                if (string.IsNullOrWhiteSpace(text))
                {
                    throw new DataValidationException(Resources.Validation_PackageNameCannotBeEmpty);
                }

                var directoryPath = new DirectoryPath(Path.GetDirectoryName(Package.FullPath!)!, text);
                if (directoryPath.Exists)
                {
                    throw new DataValidationException(
                        string.Format(Resources.ValidationError_PackageExists, text)
                    );
                }
            },
        };

        var result = await DialogHelper.GetTextEntryDialogResultAsync(
            field,
            string.Format(Resources.Description_RenamePackage, currentName)
        );

        if (result.Result == ContentDialogResult.Primary && field.IsValid && field.Text != currentName)
        {
            var newPackagePath = new DirectoryPath(Path.GetDirectoryName(Package.FullPath!)!, field.Text);
            var existingPath = new DirectoryPath(Package.FullPath!);
            if (existingPath.FullPath == newPackagePath.FullPath)
                return;

View on GitHub (pinned to af93d6ef57)