https://mattermost.atlassian.net/browse/MM-52216
```release-note
NONE
```
Этот коммит содержится в:
Agniva De Sarker
2023-04-21 22:23:56 +05:30
коммит произвёл GitHub
родитель 041cbe2d24
Коммит 67735be261
6 изменённых файлов: 34 добавлений и 10 удалений

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

@@ -251,6 +251,8 @@ type AppError struct {
wrapped error
}
const maxErrorLength = 1024
func (er *AppError) Error() string {
var sb strings.Builder
@@ -276,7 +278,11 @@ func (er *AppError) Error() string {
sb.WriteString(err.Error())
}
return sb.String()
res := sb.String()
if len(res) > maxErrorLength {
res = res[:maxErrorLength] + "..."
}
return res
}
func (er *AppError) Translate(T i18n.TranslateFunc) {

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

@@ -116,6 +116,13 @@ func TestAppErrorRender(t *testing.T) {
aerr := NewAppError("here", "message", nil, "details", http.StatusTeapot).Wrap(fmt.Errorf("my error (%w)", fmt.Errorf("inner error")))
assert.EqualError(t, aerr, "here: message, details, my error (inner error)")
})
t.Run("MaxLength", func(t *testing.T) {
str := strings.Repeat("error", 65536)
msg := "msg"
aerr := NewAppError("id", msg, nil, str, http.StatusTeapot).Wrap(errors.New(str))
assert.Len(t, aerr.Error(), maxErrorLength+len(msg))
})
}
func TestAppErrorSerialize(t *testing.T) {