{"record":{"id":"499c4970541246b4","repo":"kgrzybek/modular-monolith-with-ddd","slug":"validator-error-messages-499c49","errorCode":null,"errorMessage":"{validator error messages}","messagePattern":"\\{validator error messages\\}","errorType":"validation","errorClass":"InvalidCommandException","httpStatus":400,"severity":"warning","filePath":"src/Modules/Registrations/Infrastructure/Configuration/Processing/ValidationCommandHandlerDecorator.cs","lineNumber":32,"sourceCode":"        public ValidationCommandHandlerDecorator(\n            IList<IValidator<T>> validators,\n            ICommandHandler<T> decorated)\n        {\n            this._validators = validators;\n            _decorated = decorated;\n        }\n\n        public async Task Handle(T command, CancellationToken cancellationToken)\n        {\n            var errors = _validators\n                .Select(v => v.Validate(command))\n                .SelectMany(result => result.Errors)\n                .Where(error => error != null)\n                .ToList();\n\n            if (errors.Any())\n            {\n                throw new InvalidCommandException(errors.Select(x => x.ErrorMessage).ToList());\n            }\n\n            await _decorated.Handle(command, cancellationToken);\n        }\n    }\n}","sourceCodeStart":14,"sourceCodeEnd":38,"githubUrl":"https://github.com/kgrzybek/modular-monolith-with-ddd/blob/91c8ef24b4cb6ef558c95d8267fa07d68c7059f8/src/Modules/Registrations/Infrastructure/Configuration/Processing/ValidationCommandHandlerDecorator.cs#L14-L38","documentation":"Thrown by the Registrations module ValidationCommandHandlerDecorator. It wraps every Registrations command handler, runs all FluentValidation validators for command T, collects ErrorMessages, and throws InvalidCommandException(errors) on any failure. The '{validator error messages}' placeholder resolves to the actual validator messages.","triggerScenarios":"Sending a Registrations command (e.g. register member, confirm registration) with properties failing a registered validator: empty login/email, password below policy, missing meeting group id, invalid invite token.","commonSituations":"Public registration form submits an invalid email/weak password; admin invites with a blank email; test omits required registration fields.","solutions":["Inspect ex.Errors for the failing validators and properties.","Correct the command values (valid email, password policy, required ids).","Mirror validators on the client to fail fast.","Update validators if a legitimate value is rejected."],"exampleFix":"// before\nawait _commandDispatcher.SendAsync(new RegisterNewUserCommand(\"\", \"weak\", \"\"));\n\n// after\nawait _commandDispatcher.SendAsync(new RegisterNewUserCommand(\"user@example.com\", \"StrongP@ss1!\", \"user\"));","handlingStrategy":"validation","validationCode":"var validator = new RegisterNewUserCommandValidator();\nvar result = await validator.ValidateAsync(cmd);\nif (!result.IsValid) return BadRequest(result.Errors.Select(e => e.ErrorMessage));\nawait _commandDispatcher.SendAsync(cmd);","typeGuard":null,"tryCatchPattern":"try { await _commandDispatcher.SendAsync(cmd); }\ncatch (InvalidCommandException ex)\n{ return BadRequest(new { errors = ex.Errors }); }","preventionTips":["Mirror registration validators (email format, password policy) on the form.","Read ex.Errors for specifics.","Reject obviously empty required fields before submit."],"tags":["registrations","validation","fluentvalidation","command-handler","invalid-command-exception","decorator"],"backgroundTag":null,"analyzedSha":"91c8ef24b4cb6ef558c95d8267fa07d68c7059f8","analyzedAt":"2026-08-13T17:18:16.571Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}