Hive
fix(server): surface validation error when bundle size alert branch is blank
GitHub issue · Closed
What changed
Saving a Bundle size alert rule with the Branch field left blank now surfaces an inline Branch is required. error instead of silently doing nothing. Both the create and update handlers in ProjectNotificationsLive handle the {:error, changeset} case gracefully, keeping the modal open and the user’s input intact. The error clears as soon as the user types a branch or switches the category away from Bundle size.
Why
A user reported: saving a bundle size alert without a branch shows no error, but no alert is added.
The validation itself was already correct: AlertRule.changeset/2 requires git_branch for :bundle_size alerts, and Alerts.create_alert_rule/1 / update_alert_rule/2 correctly return {:error, changeset}. The bug was one layer up, in the LiveView event handlers:
{:ok, _alert_rule} = Alerts.create_alert_rule(attrs)
{:ok, _alert_rule} = Alerts.update_alert_rule(alert_rule, attrs)
A blank branch makes the changeset invalid, so the call returns {:error, changeset}. The hardcoded {:ok, _} match then raised a MatchError, crashing the LiveView process. The client silently remounted, resetting the modal with no flash and no alert. From the user’s perspective: “I can save, no error shows, nothing gets added.”
Root cause
Unhandled {:error, changeset} in create_alert_rule and update_alert_rule event handlers. The crash was masked by LiveView’s automatic remount, which is why it presented as a silent no-op rather than a visible error.
Why this solution
Surfacing an inline field error (rather than just disabling the submit button) matches the existing convention in authentication_settings_live (“Token name is required.”) and tells the user why the save was rejected. The error is wired through Noora text_input‘s error attribute. Handling {:error, changeset} in the handler (not only guarding the button) also means the form can never again silently swallow a submit, even for validation failures the button guard doesn’t cover.
User impact
Bundle size alerts can no longer be “saved” into a void. A missing branch produces a clear, actionable error and the modal stays open so the user can fix it.
Validation
Written TDD-style:
- Added two regression tests in
project_notifications_live_test.exs(create with blank branch; update clearing an existing branch). Ran them first against the unpatched code: both reproduced theMatchErrorongit_branch: {"can't be blank", ...}, confirming the root cause. - Applied the fix.
- Re-ran: 12/12 notifications live tests pass; 52/52 across the notifications live + alerts context suites pass.
mix credoclean on the changed module; formatted.
mix gettext.extract was run for the new Branch is required. string (only .pot updated, no .po files touched).