kgrzybek/modular-monolith-with-ddd · warning · InvalidCommandException
{validator error messages}
Error message
{validator error messages} What it means
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.
Source
Thrown at src/Modules/Registrations/Infrastructure/Configuration/Processing/ValidationCommandHandlerWithResultDecorator.cs:33
public ValidationCommandHandlerWithResultDecorator(
IList<IValidator<T>> validators,
ICommandHandler<T, TResult> decorated)
{
this._validators = validators;
_decorated = decorated;
}
public Task<TResult> Handle(T command, CancellationToken cancellationToken)
{
var errors = _validators
.Select(v => v.Validate(command))
.SelectMany(result => result.Errors)
.Where(error => error != null)
.ToList();
if (errors.Any())
{
throw new InvalidCommandException(errors.Select(x => x.ErrorMessage).ToList());
}
return _decorated.Handle(command, cancellationToken);
}
}
}View on GitHub (pinned to 91c8ef24b4)
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.
Example fix
// before
var regId = await _commandDispatcher.SendAsync(new ConfirmRegistrationCommand(""));
// after
var regId = await _commandDispatcher.SendAsync(new ConfirmRegistrationCommand(validToken)); Defensive patterns
Strategy: validation
Validate before calling
var validator = new ConfirmRegistrationCommandValidator(); var result = await validator.ValidateAsync(cmd); if (!result.IsValid) return BadRequest(result.Errors.Select(e => e.ErrorMessage)); var id = await _commandDispatcher.SendAsync(cmd);
Try / catch
try { var id = await _commandDispatcher.SendAsync(cmd); }
catch (InvalidCommandException ex)
{ return BadRequest(new { errors = ex.Errors }); } Prevention
- Validate tokens/emails client-side before dispatch.
- Inspect ex.Errors for failing properties.
- Keep validators aligned with command DTO changes.
When it happens
Trigger: Sending a Registrations command that returns a result with properties that fail a registered validator.
Common situations: Registration confirmation/invitation commands with missing or malformed tokens, emails, or ids.
Related errors
- {validator error messages}
- {validator error messages}
- {validator error messages}
- Command validation error
- Command validation error
AI-assisted analysis of kgrzybek/modular-monolith-with-ddd@91c8ef24b4 (2026-08-13).
Data as JSON: /api/errors/6d87cec0dc81a802.
Report an issue: GitHub.