kgrzybek/modular-monolith-with-ddd · error · InvalidCommandException

Meeting commenting configuration for enabling commenting mus

Error message

Meeting commenting configuration for enabling commenting must exist.

What it means

Thrown by EnableMeetingCommentingConfigurationCommandHandler when GetByMeetingIdAsync returns null. The handler needs an existing MeetingCommentingConfiguration to call EnableCommenting on; without one there is nothing to enable, so it rejects the command with InvalidCommandException (HTTP 400).

Source

Thrown at src/Modules/Meetings/Application/MeetingCommentingConfigurations/EnableMeetingCommentingConfiguration/EnableMeetingCommentingConfigurationCommandHandler.cs:34

        public EnableMeetingCommentingConfigurationCommandHandler(
            IMeetingCommentingConfigurationRepository meetingCommentingConfigurationRepository,
            IMeetingRepository meetingRepository,
            IMeetingGroupRepository meetingGroupRepository,
            IMemberContext memberContext)
        {
            _meetingCommentingConfigurationRepository = meetingCommentingConfigurationRepository;
            _meetingRepository = meetingRepository;
            _meetingGroupRepository = meetingGroupRepository;
            _memberContext = memberContext;
        }

        public async Task Handle(EnableMeetingCommentingConfigurationCommand command, CancellationToken cancellationToken)
        {
            var meetingCommentingConfiguration = await _meetingCommentingConfigurationRepository.GetByMeetingIdAsync(new MeetingId(command.MeetingId));
            if (meetingCommentingConfiguration == null)
            {
                throw new InvalidCommandException(["Meeting commenting configuration for enabling commenting must exist."]);
            }

            var meeting = await _meetingRepository.GetByIdAsync(new MeetingId(command.MeetingId));

            var meetingGroup = await _meetingGroupRepository.GetByIdAsync(meeting.GetMeetingGroupId());

            meetingCommentingConfiguration.EnableCommenting(_memberContext.MemberId, meetingGroup);
        }
    }
}

View on GitHub (pinned to 91c8ef24b4)

Solutions

  1. Verify the MeetingId exists and its commenting configuration row is present.
  2. Re-create the meeting/configuration if it is legitimately missing instead of enabling.
  3. Pre-check existence in the controller and return 404 before sending the command.
  4. Map InvalidCommandException to a 400/404 response at the API boundary.

Example fix

// before
await _commandDispatcher.SendAsync(new EnableMeetingCommentingConfigurationCommand(meetingId));

// after
var exists = await _meetingQueries.ConfigurationExistsForMeetingAsync(meetingId);
if (!exists) return NotFound("Commenting configuration not found for meeting.");
await _commandDispatcher.SendAsync(new EnableMeetingCommentingConfigurationCommand(meetingId));
Defensive patterns

Strategy: validation

Validate before calling

var exists = await _meetingQueries.ConfigurationExistsForMeetingAsync(meetingId);
if (!exists) return NotFound("Commenting configuration not found for meeting.");
await _commandDispatcher.SendAsync(new EnableMeetingCommentingConfigurationCommand(meetingId));

Type guard

public static bool IsValidMeetingId(EnableMeetingCommentingConfigurationCommand c) =>
    c.MeetingId != Guid.Empty;

Try / catch

try { await _commandDispatcher.SendAsync(cmd); }
catch (InvalidCommandException ex) when (ex.Errors.Any(m => m.Contains("must exist")))
{ return NotFound(new { errors = ex.Errors }); }

Prevention

When it happens

Trigger: Dispatching EnableMeetingCommentingConfigurationCommand with a MeetingId that has no configuration aggregate: empty Guid, non-existent meeting, deleted configuration, or enable called before the meeting's configuration was created.

Common situations: Re-enabling comments on a meeting that was archived/deleted; test fixtures that build a meeting without its configuration; UI state out of sync with the database after a failed creation.

Related errors


AI-assisted analysis of kgrzybek/modular-monolith-with-ddd@91c8ef24b4 (2026-08-13). Data as JSON: /api/errors/8fa9dec9e965515d. Report an issue: GitHub.