fix(notifications): don't render release notifications with missing repo/release #40
No reviewers
Labels
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
codefloe/forgejo-codefloe!40
Loading…
Reference in a new issue
No description provided.
Delete branch "fix/notifications-nil-repo-release"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Problem
Opening
/notifications500s with:Root cause
In
getNotifications(routers/web/user/notification.go), each release notification's repo/release is loaded in a loop that only logs andcontinues on failure — but the notification stays inreleaseNotificationsand is still appended to the unified list with a nilRepo/Release.The template then evaluates
{{.Repo.Link}}.Link()runs on a nil*Repositoryreceiver and dereferencesrepo.OwnerName, panicking. This happens when a notified release or its repository was deleted.The issue/PR path already filters failures via
notifications.Without(failures); the release path did not.Fix
{{if and .Repo .Release}}so a nil value can never panic the whole page again.go buildandgo vet ./routers/web/user/pass; template control flow is balanced.A release notification whose repository or release can no longer be loaded (e.g. it was deleted) was still appended to the unified notification list with a nil Repo/Release. The template then evaluated `{{.Repo.Link}}`, calling `Link()` on a nil `*Repository` receiver, which dereferences `repo.OwnerName` and panics — taking down the entire /notifications page with a 500. Drop such notifications in `getNotifications` instead of only logging and continuing, and count them towards the existing "removed due to missing parts" flash message. As defense-in-depth, also guard the release block in the template with `{{if and .Repo .Release}}` so a nil value can never panic the whole page again.