chore: refactor: error cause type.

This commit is contained in:
Jakub
2023-03-08 11:17:51 +01:00
parent 7cc2f3361d
commit d926dd3806
3 changed files with 12 additions and 3 deletions

View File

@ -148,7 +148,7 @@ func (bridge *Bridge) handleUserBadEvent(_ context.Context, user *user.User, eve
"new_event_id": event.NewEventID,
"event_info": event.EventInfo,
"error": event.Error,
"error_type": fmt.Sprintf("%T", internal.ErrCause(event.Error)),
"error_type": internal.ErrCauseType(event.Error),
}); rerr != nil {
logrus.WithError(rerr).Error("Failed to report failed event handling")
}
@ -164,7 +164,7 @@ func (bridge *Bridge) handleUserBadEvent(_ context.Context, user *user.User, eve
func (bridge *Bridge) handleUncategorizedErrorEvent(event events.UncategorizedEventError) {
if rerr := bridge.reporter.ReportMessageWithContext("Failed to handle due to uncategorized error", reporter.Context{
"error_type": fmt.Sprintf("%T", internal.ErrCause(event.Error)),
"error_type": internal.ErrCauseType(event.Error),
"error": event.Error,
}); rerr != nil {
logrus.WithError(rerr).Error("Failed to report failed event handling")

View File

@ -17,7 +17,10 @@
package internal
import "errors"
import (
"errors"
"fmt"
)
// ErrCause returns the cause of the error, the inner-most error in the wrapped chain.
func ErrCause(err error) error {
@ -29,3 +32,7 @@ func ErrCause(err error) error {
return cause
}
func ErrCauseType(err error) string {
return fmt.Sprintf("%T", ErrCause(err))
}

View File

@ -29,6 +29,7 @@ import (
"github.com/ProtonMail/gluon/reporter"
"github.com/ProtonMail/go-proton-api"
"github.com/ProtonMail/gopenpgp/v2/crypto"
"github.com/ProtonMail/proton-bridge/v3/internal"
"github.com/ProtonMail/proton-bridge/v3/internal/events"
"github.com/ProtonMail/proton-bridge/v3/internal/logging"
"github.com/ProtonMail/proton-bridge/v3/internal/safe"
@ -677,6 +678,7 @@ func (user *User) reportErrorAndMessageID(title string, err error, messgeID stri
func (user *User) reportErrorNoContextCancel(title string, err error, reportContext reporter.Context) {
if !errors.Is(err, context.Canceled) {
reportContext["error"] = err
reportContext["error_type"] = internal.ErrCauseType(err)
if rerr := user.reporter.ReportMessageWithContext(title, reportContext); rerr != nil {
user.log.WithError(err).WithField("title", title).Error("Failed to report message")
}