mirror of
https://github.com/go-vikunja/vikunja.git
synced 2026-03-22 21:15:18 -05:00
[PR #1379] [MERGED] Fix type assertion panics in avatar providers with graceful recovery and recursion guards #3385
Reference in New Issue
Block a user
Delete Branch "%!s()"
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?
📋 Pull Request Information
Original PR: https://github.com/go-vikunja/vikunja/pull/1379
Author: @Copilot
Created: 9/2/2025
Status: ✅ Merged
Merged: 9/2/2025
Merged by: @kolaente
Base:
main← Head:copilot/fix-1378📝 Commits (6)
fb6f0b7Initial plan71900a4Fix type assertion error in avatar upload provider with logging and graceful recoverydaeacdbFix type assertion panics in initials avatar provider with safe type assertions6b706b3Add recursion guards and refactor tests to use t.Run subtestsf5392f1fix: use require.NoError and assert.Positive in initials tests4b83b6bfix: resolve testifylint issues in avatar tests📊 Changes
4 files changed (+349 additions, -3 deletions)
View changed files
📝
pkg/modules/avatar/initials/initials.go(+48 -2)➕
pkg/modules/avatar/initials/initials_test.go(+179 -0)📝
pkg/modules/avatar/upload/upload.go(+29 -1)➕
pkg/modules/avatar/upload/upload_test.go(+93 -0)📄 Description
This PR fixes critical runtime panics that occur when the keyvalue cache contains corrupted or legacy data for avatar providers. The issues manifested as
runtime.TypeAssertionErrorcrashes in both upload and initials avatar providers:Problem
Multiple avatar providers were performing unsafe type assertions on cached data:
Upload Provider (
pkg/modules/avatar/upload/upload.go):cachedAvatar := result.(CachedAvatar)Initials Provider (
pkg/modules/avatar/initials/initials.go):cachedAvatar := result.(CachedAvatar)aa := result.(image.RGBA64)When the cache contained legacy string data or became corrupted, these would cause the application to crash instead of gracefully handling the situation.
Solution
t.Runsubtests for better organization and maintainabilityChanges
Upload Provider:
GetAvatar()to use safe type assertion with proper error handlinggetAvatarWithDepth()helper method to prevent infinite loopsAvatarFileIDto prevent nil pointer dereferencet.Runsubtests for better test organizationInitials Provider:
GetAvatar()to use safe type assertion forCachedAvatargetAvatarForUser()to use safe type assertion forimage.RGBA64getAvatarWithDepth,getAvatarForUserWithDepth)t.Runsubtests with separate test groups for better organizationBoth providers now automatically detect, log, clear, and regenerate corrupted cache entries without crashing the application. The recursion guards prevent infinite loops if cache corruption persists or regeneration continuously fails.
Fixed Sentry Issues:
interface conversion: interface {} is string, not initials.CachedAvatarinterface conversion: interface {} is string, not image.RGBA64Fixes #1378.
💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.