mirror of
https://mau.dev/mautrix/go.git
synced 2026-03-14 14:25:53 +01:00
pre-commit: ban log.Str(x.String())
This commit is contained in:
parent
3048d2edab
commit
19f3b2179c
12 changed files with 22 additions and 21 deletions
|
|
@ -27,3 +27,4 @@ repos:
|
|||
- id: prevent-literal-http-methods
|
||||
- id: zerolog-ban-global-log
|
||||
- id: zerolog-ban-msgf
|
||||
- id: zerolog-use-stringer
|
||||
|
|
|
|||
|
|
@ -360,7 +360,7 @@ func (as *AppService) NewMautrixClient(userID id.UserID) *mautrix.Client {
|
|||
AccessToken: as.Registration.AppToken,
|
||||
UserAgent: as.UserAgent,
|
||||
StateStore: as.StateStore,
|
||||
Log: as.Log.With().Str("as_user_id", userID.String()).Logger(),
|
||||
Log: as.Log.With().Stringer("as_user_id", userID).Logger(),
|
||||
Client: as.HTTPClient,
|
||||
DefaultHTTPRetries: as.DefaultHTTPRetries,
|
||||
SpecVersions: as.SpecVersions,
|
||||
|
|
|
|||
|
|
@ -201,7 +201,7 @@ func (as *AppService) handleEvents(ctx context.Context, evts []*event.Event, def
|
|||
}
|
||||
err := evt.Content.ParseRaw(evt.Type)
|
||||
if errors.Is(err, event.ErrUnsupportedContentType) {
|
||||
log.Debug().Str("event_id", evt.ID.String()).Msg("Not parsing content of unsupported event")
|
||||
log.Debug().Stringer("event_id", evt.ID).Msg("Not parsing content of unsupported event")
|
||||
} else if err != nil {
|
||||
log.Warn().Err(err).
|
||||
Str("event_id", evt.ID.String()).
|
||||
|
|
|
|||
|
|
@ -157,12 +157,12 @@ func (helper *CryptoHelper) resyncEncryptionInfo(ctx context.Context) {
|
|||
var evt event.EncryptionEventContent
|
||||
err = helper.client.StateEvent(ctx, roomID, event.StateEncryption, "", &evt)
|
||||
if err != nil {
|
||||
log.Err(err).Str("room_id", roomID.String()).Msg("Failed to get encryption event")
|
||||
log.Err(err).Stringer("room_id", roomID).Msg("Failed to get encryption event")
|
||||
_, err = helper.store.DB.Exec(ctx, `
|
||||
UPDATE mx_room_state SET encryption=NULL WHERE room_id=$1 AND encryption='{"resync":true}'
|
||||
`, roomID)
|
||||
if err != nil {
|
||||
log.Err(err).Str("room_id", roomID.String()).Msg("Failed to unmark room for resync after failed sync")
|
||||
log.Err(err).Stringer("room_id", roomID).Msg("Failed to unmark room for resync after failed sync")
|
||||
}
|
||||
} else {
|
||||
maxAge := evt.RotationPeriodMillis
|
||||
|
|
@ -185,9 +185,9 @@ func (helper *CryptoHelper) resyncEncryptionInfo(ctx context.Context) {
|
|||
WHERE room_id=$3 AND max_age IS NULL AND max_messages IS NULL
|
||||
`, maxAge, maxMessages, roomID)
|
||||
if err != nil {
|
||||
log.Err(err).Str("room_id", roomID.String()).Msg("Failed to update megolm session table")
|
||||
log.Err(err).Stringer("room_id", roomID).Msg("Failed to update megolm session table")
|
||||
} else {
|
||||
log.Debug().Str("room_id", roomID.String()).Msg("Updated megolm session table")
|
||||
log.Debug().Stringer("room_id", roomID).Msg("Updated megolm session table")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -233,7 +233,7 @@ func (helper *CryptoHelper) loginBot(ctx context.Context) (*mautrix.Client, bool
|
|||
if err != nil {
|
||||
return nil, false, fmt.Errorf("failed to find existing device ID: %w", err)
|
||||
} else if len(deviceID) > 0 {
|
||||
helper.log.Debug().Str("device_id", deviceID.String()).Msg("Found existing device ID for bot in database")
|
||||
helper.log.Debug().Stringer("device_id", deviceID).Msg("Found existing device ID for bot in database")
|
||||
}
|
||||
// Create a new client instance with the default AS settings (including as_token),
|
||||
// the Login call will then override the access token in the client.
|
||||
|
|
|
|||
|
|
@ -1785,7 +1785,7 @@ func (cli *Client) UploadAsync(ctx context.Context, req ReqUploadMedia) (*RespCr
|
|||
go func() {
|
||||
_, err = cli.UploadMedia(ctx, req)
|
||||
if err != nil {
|
||||
cli.Log.Error().Str("mxc", req.MXC.String()).Err(err).Msg("Async upload of media failed")
|
||||
cli.Log.Error().Stringer("mxc", req.MXC).Err(err).Msg("Async upload of media failed")
|
||||
}
|
||||
}()
|
||||
return resp, nil
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ import (
|
|||
func (mach *OlmMachine) storeCrossSigningKeys(ctx context.Context, crossSigningKeys map[id.UserID]mautrix.CrossSigningKeys, deviceKeys map[id.UserID]map[id.DeviceID]mautrix.DeviceKeys) {
|
||||
log := mach.machOrContextLog(ctx)
|
||||
for userID, userKeys := range crossSigningKeys {
|
||||
log := log.With().Str("user_id", userID.String()).Logger()
|
||||
log := log.With().Stringer("user_id", userID).Logger()
|
||||
currentKeys, err := mach.CryptoStore.GetCrossSigningKeys(ctx, userID)
|
||||
if err != nil {
|
||||
log.Error().Err(err).
|
||||
|
|
@ -28,7 +28,7 @@ func (mach *OlmMachine) storeCrossSigningKeys(ctx context.Context, crossSigningK
|
|||
}
|
||||
if currentKeys != nil {
|
||||
for curKeyUsage, curKey := range currentKeys {
|
||||
log := log.With().Str("old_key", curKey.Key.String()).Str("old_key_usage", string(curKeyUsage)).Logger()
|
||||
log := log.With().Stringer("old_key", curKey.Key).Str("old_key_usage", string(curKeyUsage)).Logger()
|
||||
// got a new key with the same usage as an existing key
|
||||
for _, newKeyUsage := range userKeys.Usage {
|
||||
if newKeyUsage == curKeyUsage {
|
||||
|
|
@ -49,7 +49,7 @@ func (mach *OlmMachine) storeCrossSigningKeys(ctx context.Context, crossSigningK
|
|||
}
|
||||
|
||||
for _, key := range userKeys.Keys {
|
||||
log := log.With().Str("key", key.String()).Array("usages", exzerolog.ArrayOfStrs(userKeys.Usage)).Logger()
|
||||
log := log.With().Stringer("key", key).Array("usages", exzerolog.ArrayOfStrs(userKeys.Usage)).Logger()
|
||||
for _, usage := range userKeys.Usage {
|
||||
log.Trace().Str("usage", string(usage)).Msg("Storing cross-signing key")
|
||||
if err = mach.CryptoStore.PutCrossSigningKey(ctx, userID, usage, key); err != nil {
|
||||
|
|
|
|||
|
|
@ -340,7 +340,7 @@ func (mach *OlmMachine) unwedgeDevice(log zerolog.Logger, sender id.UserID, send
|
|||
return
|
||||
}
|
||||
|
||||
log.Debug().Str("device_id", deviceIdentity.DeviceID.String()).Msg("Creating new Olm session")
|
||||
log.Debug().Stringer("device_id", deviceIdentity.DeviceID).Msg("Creating new Olm session")
|
||||
mach.devicesToUnwedgeLock.Lock()
|
||||
mach.devicesToUnwedge[senderKey] = true
|
||||
mach.devicesToUnwedgeLock.Unlock()
|
||||
|
|
|
|||
|
|
@ -206,7 +206,7 @@ func (mach *OlmMachine) FetchKeys(ctx context.Context, users []id.UserID, includ
|
|||
log.Trace().Int("user_count", len(resp.DeviceKeys)).Msg("Query key result received")
|
||||
data = make(map[id.UserID]map[id.DeviceID]*id.Device)
|
||||
for userID, devices := range resp.DeviceKeys {
|
||||
log := log.With().Str("user_id", userID.String()).Logger()
|
||||
log := log.With().Stringer("user_id", userID).Logger()
|
||||
delete(req.DeviceKeys, userID)
|
||||
|
||||
newDevices := make(map[id.DeviceID]*id.Device)
|
||||
|
|
@ -222,7 +222,7 @@ func (mach *OlmMachine) FetchKeys(ctx context.Context, users []id.UserID, includ
|
|||
Msg("Updating devices in store")
|
||||
changed := false
|
||||
for deviceID, deviceKeys := range devices {
|
||||
log := log.With().Str("device_id", deviceID.String()).Logger()
|
||||
log := log.With().Stringer("device_id", deviceID).Logger()
|
||||
existing, ok := existingDevices[deviceID]
|
||||
if !ok {
|
||||
// New device
|
||||
|
|
@ -270,7 +270,7 @@ func (mach *OlmMachine) FetchKeys(ctx context.Context, users []id.UserID, includ
|
|||
}
|
||||
}
|
||||
for userID := range req.DeviceKeys {
|
||||
log.Warn().Str("user_id", userID.String()).Msg("Didn't get any keys for user")
|
||||
log.Warn().Stringer("user_id", userID).Msg("Didn't get any keys for user")
|
||||
}
|
||||
|
||||
mach.storeCrossSigningKeys(ctx, resp.MasterKeys, resp.DeviceKeys)
|
||||
|
|
|
|||
|
|
@ -233,7 +233,7 @@ func (mach *OlmMachine) ShareGroupSession(ctx context.Context, roomID id.RoomID,
|
|||
var fetchKeysForUsers []id.UserID
|
||||
|
||||
for _, userID := range users {
|
||||
log := log.With().Str("target_user_id", userID.String()).Logger()
|
||||
log := log.With().Stringer("target_user_id", userID).Logger()
|
||||
devices, err := mach.CryptoStore.GetDevices(ctx, userID)
|
||||
if err != nil {
|
||||
log.Err(err).Msg("Failed to get devices of user")
|
||||
|
|
@ -305,7 +305,7 @@ func (mach *OlmMachine) ShareGroupSession(ctx context.Context, roomID id.RoomID,
|
|||
toDeviceWithheld.Messages[userID] = withheld
|
||||
}
|
||||
|
||||
log := log.With().Str("target_user_id", userID.String()).Logger()
|
||||
log := log.With().Stringer("target_user_id", userID).Logger()
|
||||
log.Trace().Msg("Trying to find olm session to encrypt megolm session for user (post-fetch retry)")
|
||||
mach.findOlmSessionsForUser(ctx, session, userID, devices, output, withheld, nil)
|
||||
log.Debug().
|
||||
|
|
|
|||
|
|
@ -361,7 +361,7 @@ func (mach *OlmMachine) HandleMemberEvent(ctx context.Context, evt *event.Event)
|
|||
Msg("Got membership state change, invalidating group session in room")
|
||||
err := mach.CryptoStore.RemoveOutboundGroupSession(ctx, evt.RoomID)
|
||||
if err != nil {
|
||||
mach.Log.Warn().Str("room_id", evt.RoomID.String()).Msg("Failed to invalidate outbound group session")
|
||||
mach.Log.Warn().Stringer("room_id", evt.RoomID).Msg("Failed to invalidate outbound group session")
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -581,7 +581,7 @@ func (mach *OlmMachine) createGroupSession(ctx context.Context, senderKey id.Sen
|
|||
}
|
||||
err = mach.CryptoStore.PutGroupSession(ctx, igs)
|
||||
if err != nil {
|
||||
log.Err(err).Str("session_id", sessionID.String()).Msg("Failed to store new inbound group session")
|
||||
log.Err(err).Stringer("session_id", sessionID).Msg("Failed to store new inbound group session")
|
||||
return fmt.Errorf("failed to store new inbound group session: %w", err)
|
||||
}
|
||||
mach.MarkSessionReceived(ctx, roomID, sessionID, igs.Internal.FirstKnownIndex())
|
||||
|
|
|
|||
|
|
@ -695,7 +695,7 @@ func (vh *VerificationHelper) onVerificationMAC(ctx context.Context, txn Verific
|
|||
// Verify the MAC for each key
|
||||
var theirDevice *id.Device
|
||||
for keyID, mac := range macEvt.MAC {
|
||||
log.Info().Str("key_id", keyID.String()).Msg("Received MAC for key")
|
||||
log.Info().Stringer("key_id", keyID).Msg("Received MAC for key")
|
||||
|
||||
alg, kID := keyID.Parse()
|
||||
if alg != id.KeyAlgorithmEd25519 {
|
||||
|
|
|
|||
|
|
@ -143,7 +143,7 @@ func main() {
|
|||
if err != nil {
|
||||
log.Error().Err(err).Msg("Failed to send event")
|
||||
} else {
|
||||
log.Info().Str("event_id", resp.EventID.String()).Msg("Event sent")
|
||||
log.Info().Stringer("event_id", resp.EventID).Msg("Event sent")
|
||||
}
|
||||
}
|
||||
cancelSync()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue