[MM-58020] Improve error message of NotFound errors in store (#26870)

* Improve error message of NotFound errors in store

* update mmctl tests
Этот коммит содержится в:
Ben Schumacher
2024-05-07 15:30:48 +02:00
коммит произвёл GitHub
родитель d6543b9bd5
Коммит 09c39cf3ec
4 изменённых файлов: 37 добавлений и 9 удалений

Просмотреть файл

@@ -120,10 +120,10 @@ func (e *ErrNotFound) Wrap(err error) *ErrNotFound {
func (e *ErrNotFound) Error() string {
if e.wrapped != nil {
return fmt.Sprintf("resource: %s id: %s error: %s", e.resource, e.ID, e.wrapped)
return fmt.Sprintf("resource %q not found, id: %s, error: %s", e.resource, e.ID, e.wrapped)
}
return fmt.Sprintf("resource: %s id: %s", e.resource, e.ID)
return fmt.Sprintf("resource %q not found, id: %s", e.resource, e.ID)
}
// IsErrNotFound allows easy type assertion without adding store as a dependency.

28
server/channels/store/errors_test.go Обычный файл
Просмотреть файл

@@ -0,0 +1,28 @@
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
package store
import (
"errors"
"testing"
"github.com/mattermost/mattermost/server/public/model"
"github.com/stretchr/testify/assert"
)
func TestErrNotFound(t *testing.T) {
id := model.NewId()
t.Run("plain", func(t *testing.T) {
err := NewErrNotFound("channel", id)
assert.EqualError(t, err, "resource \"channel\" not found, id: "+id)
})
t.Run("with wrapped error", func(t *testing.T) {
err := NewErrNotFound("channel", id)
err = err.Wrap(errors.New("some error"))
assert.EqualError(t, err, "resource \"channel\" not found, id: "+id+", error: some error")
})
}