Fix panic on DB error (#15310)
Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
6a50106cd9
Коммит
e6c1d5f75b
@@ -2644,7 +2644,7 @@ func (a *App) createInitialSidebarCategories(userId, teamId string) *model.AppEr
|
|||||||
func (a *App) GetSidebarCategories(userId, teamId string) (*model.OrderedSidebarCategories, *model.AppError) {
|
func (a *App) GetSidebarCategories(userId, teamId string) (*model.OrderedSidebarCategories, *model.AppError) {
|
||||||
categories, err := a.Srv().Store.Channel().GetSidebarCategories(userId, teamId)
|
categories, err := a.Srv().Store.Channel().GetSidebarCategories(userId, teamId)
|
||||||
|
|
||||||
if len(categories.Categories) == 0 && err == nil {
|
if err == nil && len(categories.Categories) == 0 {
|
||||||
// A user must always have categories, so migration must not have happened yet, and we should run it ourselves
|
// A user must always have categories, so migration must not have happened yet, and we should run it ourselves
|
||||||
nErr := a.createInitialSidebarCategories(userId, teamId)
|
nErr := a.createInitialSidebarCategories(userId, teamId)
|
||||||
if nErr != nil {
|
if nErr != nil {
|
||||||
|
|||||||
@@ -1999,4 +1999,23 @@ func TestGetSidebarCategories(t *testing.T) {
|
|||||||
assert.Nil(t, err)
|
assert.Nil(t, err)
|
||||||
assert.Len(t, categories.Categories, 3)
|
assert.Len(t, categories.Categories, 3)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
t.Run("should return a store error if a db table is missing", func(t *testing.T) {
|
||||||
|
th := Setup(t).InitBasic()
|
||||||
|
defer th.TearDown()
|
||||||
|
|
||||||
|
// Temporarily renaming a table to force a DB error.
|
||||||
|
sqlSupplier := mainHelper.GetSQLSupplier()
|
||||||
|
_, err := sqlSupplier.GetMaster().Exec("ALTER TABLE SidebarCategories RENAME TO SidebarCategoriesTest")
|
||||||
|
require.Nil(t, err)
|
||||||
|
defer func() {
|
||||||
|
_, err := sqlSupplier.GetMaster().Exec("ALTER TABLE SidebarCategoriesTest RENAME TO SidebarCategories")
|
||||||
|
require.Nil(t, err)
|
||||||
|
}()
|
||||||
|
|
||||||
|
categories, appErr := th.App.GetSidebarCategories(th.BasicUser.Id, th.BasicTeam.Id)
|
||||||
|
assert.Nil(t, categories)
|
||||||
|
assert.NotNil(t, appErr)
|
||||||
|
assert.Equal(t, "store.sql_channel.sidebar_categories.app_error", appErr.Id)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user