{"record":{"id":"caa48646ad2aa195","repo":"kgrzybek/modular-monolith-with-ddd","slug":"meeting-comment-for-editing-must-exist","errorCode":null,"errorMessage":"Meeting comment for editing must exist.","messagePattern":"Meeting comment for editing must exist\\.","errorType":"validation","errorClass":"InvalidCommandException","httpStatus":400,"severity":"error","filePath":"src/Modules/Meetings/Application/MeetingComments/EditMeetingComment/EditMeetingCommentCommandHandler.cs","lineNumber":30,"sourceCode":"        private readonly IMeetingCommentingConfigurationRepository _meetingCommentingConfigurationRepository;\r\n        private readonly IMemberContext _memberContext;\r\n\r\n        internal EditMeetingCommentCommandHandler(\r\n            IMeetingCommentRepository meetingCommentRepository,\r\n            IMeetingCommentingConfigurationRepository meetingCommentingConfigurationRepository,\r\n            IMemberContext memberContext)\r\n        {\r\n            _meetingCommentRepository = meetingCommentRepository;\r\n            _meetingCommentingConfigurationRepository = meetingCommentingConfigurationRepository;\r\n            _memberContext = memberContext;\r\n        }\r\n\r\n        public async Task Handle(EditMeetingCommentCommand command, CancellationToken cancellationToken)\r\n        {\r\n            var meetingComment = await _meetingCommentRepository.GetByIdAsync(new MeetingCommentId(command.MeetingCommentId));\r\n            if (meetingComment == null)\r\n            {\r\n                throw new InvalidCommandException([\"Meeting comment for editing must exist.\"]);\r\n            }\r\n\r\n            var meetingCommentingConfiguration = await _meetingCommentingConfigurationRepository.GetByMeetingIdAsync(meetingComment.GetMeetingId());\r\n\r\n            meetingComment.Edit(_memberContext.MemberId, command.EditedComment, meetingCommentingConfiguration);\r\n        }\r\n    }\r\n}","sourceCodeStart":12,"sourceCodeEnd":38,"githubUrl":"https://github.com/kgrzybek/modular-monolith-with-ddd/blob/91c8ef24b4cb6ef558c95d8267fa07d68c7059f8/src/Modules/Meetings/Application/MeetingComments/EditMeetingComment/EditMeetingCommentCommandHandler.cs#L12-L38","documentation":"Thrown by EditMeetingCommentCommandHandler when GetByIdAsync returns null for the MeetingCommentId. Editing requires an existing comment to load its commenting configuration and apply the change; a missing comment aborts with InvalidCommandException (HTTP 400).","triggerScenarios":"Dispatching EditMeetingCommentCommand for a comment id that does not exist or was removed: stale edit link, concurrent removal, wrong id.","commonSituations":"User opens an edit form for a comment that another flow deleted; client caches comment ids across sessions.","solutions":["Confirm the comment still exists before offering the edit action.","Pre-check existence in the controller and return 404.","Disable the edit UI when the comment is no longer present.","Map InvalidCommandException to 400/404 at the API boundary."],"exampleFix":"// before\nawait _commandDispatcher.SendAsync(new EditMeetingCommentCommand(commentId, newText));\n\n// after\nvar comment = await _meetingQueries.GetCommentAsync(commentId);\nif (comment is null) return NotFound(\"Comment not found.\");\nawait _commandDispatcher.SendAsync(new EditMeetingCommentCommand(commentId, newText));","handlingStrategy":"validation","validationCode":"var comment = await _meetingQueries.GetCommentAsync(commentId);\nif (comment is null) return NotFound(\"Comment not found.\");\nawait _commandDispatcher.SendAsync(new EditMeetingCommentCommand(commentId, newText));","typeGuard":"public static bool IsValidEditCommand(EditMeetingCommentCommand c) =>\n    c.MeetingCommentId != Guid.Empty && !string.IsNullOrWhiteSpace(c.EditedComment);","tryCatchPattern":"try { await _commandDispatcher.SendAsync(cmd); }\ncatch (InvalidCommandException ex) when (ex.Errors.Any(m => m.Contains(\"must exist\")))\n{ return NotFound(new { errors = ex.Errors }); }","preventionTips":["Open the edit form only for comments confirmed present.","Discard cached comment ids on session restart.","Validate non-empty id and non-empty text client-side."],"tags":["meetings","comments","not-found","invalid-command-exception","command-handler"],"backgroundTag":null,"analyzedSha":"91c8ef24b4cb6ef558c95d8267fa07d68c7059f8","analyzedAt":"2026-08-13T17:18:16.571Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}