{"record":{"id":"39063f046d696767","repo":"LykosAI/StabilityMatrix","slug":"resources-validation-packagenamecannotbeempty","errorCode":null,"errorMessage":"Resources.Validation_PackageNameCannotBeEmpty","messagePattern":"Resources\\.Validation_PackageNameCannotBeEmpty","errorType":"validation","errorClass":"DataValidationException","httpStatus":null,"severity":"warning","filePath":"StabilityMatrix.Avalonia/ViewModels/PackageManager/PackageCardViewModel.cs","lineNumber":890,"sourceCode":"    }\n\n    [RelayCommand]\n    private async Task Rename()\n    {\n        if (Package is null || IsUnknownPackage)\n            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)","sourceCodeStart":872,"sourceCodeEnd":908,"githubUrl":"https://github.com/LykosAI/StabilityMatrix/blob/af93d6ef57c01cd890d7e0ad0a9ea8c9fcda3002/StabilityMatrix.Avalonia/ViewModels/PackageManager/PackageCardViewModel.cs#L872-L908","documentation":"In PackageCardViewModel's package rename flow, a TextBoxField.Validator lambda validates the new package name typed into the rename dialog. When the text is null/whitespace it throws DataValidationException(Resources.Validation_PackageNameCannotBeEmpty); the dialog framework catches this and shows the localized validation message instead of performing the rename. The bracketed resource key is the thrown message because DataValidationException is keyed on the localized string resource.","triggerScenarios":"Submitting (clicking Rename/OK in GetTextEntryDialogResultAsync) the rename dialog with an empty or whitespace-only display name — e.g. the user cleared the text field, pasted only spaces, or accepted the dialog before typing anything.","commonSituations":"User accidentally deletes the existing name before confirming; pasting a name consisting only of whitespace/newlines; automation or UI testing that submits the dialog with an empty TextBox; a renamed display name identical to blank after trimming.","solutions":["Type a non-empty package name in the rename dialog before confirming.","Trim the input and re-check: the name must contain at least one non-whitespace character and must not collide with an existing package directory (the validator's second check).","Cancel the dialog if you don't want to rename; the original name is kept.","If validating programmatically, mirror the validator: reject string.IsNullOrWhiteSpace(text) before calling DirectoryPath.MoveToAsync."],"exampleFix":"// before (throws inside validator)\nif (string.IsNullOrWhiteSpace(text))\n    throw new DataValidationException(Resources.Validation_PackageNameCannotBeEmpty);\n// after (caller-side pre-check)\nif (!string.IsNullOrWhiteSpace(newName) && !directoryPath.Exists)\n    await existingPath.MoveToAsync(new DirectoryPath(parentDir, newName));","handlingStrategy":"validation","validationCode":"if (string.IsNullOrWhiteSpace(newName))\n    return; // don't submit the rename dialog\nvar target = new DirectoryPath(Path.GetDirectoryName(package.FullPath!)!, newName);\nif (target.Exists) { /* name collides with existing package */ }","typeGuard":"bool IsValidPackageName(string? name) => !string.IsNullOrWhiteSpace(name);","tryCatchPattern":"var result = await DialogHelper.GetTextEntryDialogResultAsync(field, ...);\n// validator throws DataValidationException internally; the dialog surfaces it\nif (result.Result == ContentDialogResult.Primary && field.IsValid)\n    await PerformRename(field.Text);","preventionTips":["Never confirm the rename dialog with a blank name; the validator blocks it but the dialog stays open.","Trim pasted names and check they aren't pure whitespace.","Check the target directory doesn't already exist in the packages folder — the same validator rejects duplicates.","When renaming programmatically, pre-validate IsNullOrWhiteSpace and target.Exists before MoveToAsync."],"tags":["csharp","avalonia","validation","ui","rename"],"backgroundTag":"empty-required-field","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"}