{"record":{"id":"c3440359df43d69d","repo":"LykosAI/StabilityMatrix","slug":"string-format-resources-validationerror-packageexists-text","errorCode":null,"errorMessage":"string.Format(Resources.ValidationError_PackageExists, text)","messagePattern":"string\\.Format\\(Resources\\.ValidationError_PackageExists, text\\)","errorType":"validation","errorClass":"DataValidationException","httpStatus":null,"severity":"error","filePath":"StabilityMatrix.Avalonia/ViewModels/PackageManager/PackageCardViewModel.cs","lineNumber":896,"sourceCode":"            return;\n\n        var currentName = Package.DisplayName ?? Package.PackageName ?? string.Empty;\n        var field = new TextBoxField\n        {\n            Label = Resources.Label_DisplayName,\n            Text = currentName,\n            Watermark = Resources.Watermark_EnterPackageName,\n            Validator = text =>\n            {\n                if (string.IsNullOrWhiteSpace(text))\n                {\n                    throw new DataValidationException(Resources.Validation_PackageNameCannotBeEmpty);\n                }\n\n                var directoryPath = new DirectoryPath(Path.GetDirectoryName(Package.FullPath!)!, text);\n                if (directoryPath.Exists)\n                {\n                    throw new DataValidationException(\n                        string.Format(Resources.ValidationError_PackageExists, text)\n                    );\n                }\n            },\n        };\n\n        var result = await DialogHelper.GetTextEntryDialogResultAsync(\n            field,\n            string.Format(Resources.Description_RenamePackage, currentName)\n        );\n\n        if (result.Result == ContentDialogResult.Primary && field.IsValid && field.Text != currentName)\n        {\n            var newPackagePath = new DirectoryPath(Path.GetDirectoryName(Package.FullPath!)!, field.Text);\n            var existingPath = new DirectoryPath(Package.FullPath!);\n            if (existingPath.FullPath == newPackagePath.FullPath)\n                return;\n","sourceCodeStart":878,"sourceCodeEnd":914,"githubUrl":"https://github.com/LykosAI/StabilityMatrix/blob/af93d6ef57c01cd890d7e0ad0a9ea8c9fcda3002/StabilityMatrix.Avalonia/ViewModels/PackageManager/PackageCardViewModel.cs#L878-L914","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Pick a different package name that does not exist in the package install directory.","Delete or rename the conflicting folder on disk if it is a leftover from a failed operation.","Check for case-only differences if on a case-insensitive filesystem (Windows/macOS)."],"exampleFix":"// before\nthrow new DataValidationException(string.Format(Resources.ValidationError_PackageExists, text));\n// after\nvar directoryPath = new DirectoryPath(Path.GetDirectoryName(Package.FullPath!)!, text);\nif (directoryPath.Exists)\n{\n    text = text + \"-1\"; // auto-suffix or prompt user for a new name\n}","handlingStrategy":"validation","validationCode":"var target = new DirectoryPath(Path.GetDirectoryName(package.FullPath!)!, newName);\nif (string.IsNullOrWhiteSpace(newName) || target.Exists)\n    return; // block rename or prompt for another name","typeGuard":null,"tryCatchPattern":"try { await DoRenameAsync(text); }\ncatch (DataValidationException ex) { ShowDialog(\"Cannot rename\", ex.Message); }","preventionTips":["Check the target directory for existence before opening the rename dialog.","Disable the OK button until validation passes (live validator feedback).","Clean up leftover package folders after failed installs/uninstalls."],"tags":["validation","filesystem","avalonia"],"backgroundTag":"file-already-exists","analyzedSha":"af93d6ef57c01cd890d7e0ad0a9ea8c9fcda3002","analyzedAt":"2026-09-12T19:02:43.389Z","contentChangedAt":"2026-09-12T19:02:43.389Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}