{"record":{"id":"6d87cec0dc81a802","repo":"kgrzybek/modular-monolith-with-ddd","slug":"validator-error-messages-6d87ce","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/ValidationCommandHandlerWithResultDecorator.cs","lineNumber":33,"sourceCode":"        public ValidationCommandHandlerWithResultDecorator(\n            IList<IValidator<T>> validators,\n            ICommandHandler<T, TResult> decorated)\n        {\n            this._validators = validators;\n            _decorated = decorated;\n        }\n\n        public Task<TResult> 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            return _decorated.Handle(command, cancellationToken);\n        }\n    }\n}","sourceCodeStart":15,"sourceCodeEnd":39,"githubUrl":"https://github.com/kgrzybek/modular-monolith-with-ddd/blob/91c8ef24b4cb6ef558c95d8267fa07d68c7059f8/src/Modules/Registrations/Infrastructure/Configuration/Processing/ValidationCommandHandlerWithResultDecorator.cs#L15-L39","documentation":"Thrown by the Registrations module ValidationCommandHandlerWithResultDecorator (the TResult-returning variant). It runs all FluentValidation validators for command T, aggregates ErrorMessages, and throws InvalidCommandException(errors) on any failure. The placeholder '{validator error messages}' is replaced by the real validator output at throw time.","triggerScenarios":"Sending a Registrations command that returns a result with properties that fail a registered validator.","commonSituations":"Registration confirmation/invitation commands with missing or malformed tokens, emails, or ids.","solutions":["Read ex.Errors to find failing validators and properties.","Fix the command values to pass validation.","Pre-validate on the client using the same rules.","Adjust validators where a valid value is wrongly rejected."],"exampleFix":"// before\nvar regId = await _commandDispatcher.SendAsync(new ConfirmRegistrationCommand(\"\"));\n\n// after\nvar regId = await _commandDispatcher.SendAsync(new ConfirmRegistrationCommand(validToken));","handlingStrategy":"validation","validationCode":"var validator = new ConfirmRegistrationCommandValidator();\nvar result = await validator.ValidateAsync(cmd);\nif (!result.IsValid) return BadRequest(result.Errors.Select(e => e.ErrorMessage));\nvar id = await _commandDispatcher.SendAsync(cmd);","typeGuard":null,"tryCatchPattern":"try { var id = await _commandDispatcher.SendAsync(cmd); }\ncatch (InvalidCommandException ex)\n{ return BadRequest(new { errors = ex.Errors }); }","preventionTips":["Validate tokens/emails client-side before dispatch.","Inspect ex.Errors for failing properties.","Keep validators aligned with command DTO changes."],"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"}