{"record":{"id":"2ec5c0f099bcb296","repo":"elsa-workflows/elsa-core","slug":"label-name-cannot-exceed-namemaxlength-characters","errorCode":null,"errorMessage":"Label name cannot exceed {NameMaxLength} characters.","messagePattern":"Label name cannot exceed (.+?) characters\\.","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/modules/Elsa.Labels/Entities/Label.cs","lineNumber":25,"sourceCode":"/// </summary>\npublic class Label : Entity\n{\n    /// <summary>\n    /// Shared maximum for <see cref=\"Name\"/> and <see cref=\"NormalizedName\"/>.\n    /// Matches the MySQL unique-index limit that every provider's schema must honor.\n    /// </summary>\n    public const int NameMaxLength = 255;\n\n    private string _name = default!;\n\n    public string Name\n    {\n        get => _name;\n        set\n        {\n            if (value.Length > NameMaxLength)\n            {\n                throw new ArgumentException(\n                    $\"Label name cannot exceed {NameMaxLength} characters.\",\n                    nameof(Name));\n            }\n\n            _name = value;\n            NormalizedName = value.ToLowerInvariant();\n        }\n    }\n\n    public string NormalizedName { get; set; } = default!;\n    public string? Description { get; set; }\n    public string? Color { get; set; }\n}","sourceCodeStart":7,"sourceCodeEnd":38,"githubUrl":"https://github.com/elsa-workflows/elsa-core/blob/fe9217bdfa0e27f0e09e45006eb6898f616e513d/src/modules/Elsa.Labels/Entities/Label.cs#L7-L38","documentation":"The Label entity validates its Name property on assignment: if the value exceeds NameMaxLength characters, the constructor/setter throws ArgumentException naming the offending property. NormalizedName is only set after validation succeeds, so invalid labels are never partially constructed.","triggerScenarios":"Constructing new Label(name) or setting label.Name with a string longer than the Label.NameMaxLength constant, e.g. free-form user input used directly as a label name.","commonSituations":"Importing labels from external systems with lax length limits, users typing very long label names in Studio, or mapping database rows containing over-length names into Label entities after a max-length reduction in a newer version.","solutions":["Truncate or reject the name in application code before constructing/assigning: check name.Length against the max length.","Enforce a max-length validation rule in the UI/input model so over-length names never reach the entity.","If longer names must be supported, persist a custom entity or raise the limit via the applicable entity configuration rather than bypassing the check."],"exampleFix":"// before\nvar label = new Label(userInputName); // throws when userInputName too long\n// after\nconst int Max = Label.NameMaxLength;\nvar name = userInputName.Length > Max ? userInputName[..Max] : userInputName;\nvar label = new Label(name);","handlingStrategy":"validation","validationCode":"if (!string.IsNullOrEmpty(name) && name.Length > Label.NameMaxLength)\n    throw new ArgumentException($\"Label name cannot exceed {Label.NameMaxLength} characters.\", nameof(name));","typeGuard":"static bool IsValidLabelName(string? name) => !string.IsNullOrEmpty(name) && name.Length <= Label.NameMaxLength;","tryCatchPattern":"try { var label = new Label(name); }\ncatch (ArgumentException ex) when (ex.ParamName == nameof(Label.Name))\n{\n    modelState.AddModelError(\"Name\", ex.Message);\n}","preventionTips":["Validate/limit label name length at input boundaries (forms, API DTOs).","Truncate external system labels to the supported maximum on import.","Share the max-length constant with client-side validators to keep limits in sync."],"tags":["validation","labels","argument-exception","length-limit"],"backgroundTag":"value-out-of-range","analyzedSha":"fe9217bdfa0e27f0e09e45006eb6898f616e513d","analyzedAt":"2026-09-13T20:32:34.702Z","contentChangedAt":"2026-09-13T20:32:34.702Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}