mirror of
https://github.com/ProtonMail/proton-bridge.git
synced 2025-12-10 12:46:46 +00:00
chore: refactor: error cause type.
This commit is contained in:
@ -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")
|
||||
|
||||
@ -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))
|
||||
}
|
||||
|
||||
@ -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")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user