Remove some panics

This commit is contained in:
Tulir Asokan 2023-07-16 16:18:45 +03:00
parent 6225b83d2f
commit fa5928e405
2 changed files with 16 additions and 19 deletions

View file

@ -106,15 +106,14 @@ func (c *Client) Connect() error {
return fmt.Errorf("not logged in")
}
refreshErr := c.refreshAuthToken()
if refreshErr != nil {
panic(refreshErr)
err := c.refreshAuthToken()
if err != nil {
return fmt.Errorf("failed to refresh auth token: %w", err)
}
webEncryptionKeyResponse, webEncryptionKeyErr := c.GetWebEncryptionKey()
if webEncryptionKeyErr != nil {
c.Logger.Err(webEncryptionKeyErr).Any("response", webEncryptionKeyResponse).Msg("GetWebEncryptionKey request failed")
return webEncryptionKeyErr
webEncryptionKeyResponse, err := c.GetWebEncryptionKey()
if err != nil {
return fmt.Errorf("failed to get web encryption key: %w", err)
}
c.updateWebEncryptionKey(webEncryptionKeyResponse.GetKey())
go c.rpc.ListenReceiveMessages()
@ -122,12 +121,12 @@ func (c *Client) Connect() error {
bugleRes, bugleErr := c.IsBugleDefault()
if bugleErr != nil {
panic(bugleErr)
return fmt.Errorf("failed to check bugle default: %w", err)
}
c.Logger.Info().Any("isBugle", bugleRes.Success).Msg("IsBugleDefault")
c.Logger.Debug().Any("isBugle", bugleRes.Success).Msg("IsBugleDefault")
sessionErr := c.SetActiveSession()
if sessionErr != nil {
panic(sessionErr)
return fmt.Errorf("failed to set active session: %w", err)
}
return nil
}

View file

@ -1,6 +1,8 @@
package libgm
import (
"fmt"
"go.mau.fi/mautrix-gmessages/libgm/events"
"go.mau.fi/mautrix-gmessages/libgm/pblite"
@ -17,10 +19,7 @@ func (c *Client) handlePairingEvent(response *pblite.Response) {
switch evt := pairEventData.Event.(type) {
case *binary.PairEvents_Paired:
callbackErr := c.completePairing(evt.Paired)
if callbackErr != nil {
panic(callbackErr)
}
c.completePairing(evt.Paired)
case *binary.PairEvents_Revoked:
c.Logger.Debug().Any("data", evt).Msg("Revoked Device")
c.triggerEvent(evt.Revoked)
@ -29,16 +28,15 @@ func (c *Client) handlePairingEvent(response *pblite.Response) {
}
}
func (c *Client) completePairing(data *binary.PairedData) error {
func (c *Client) completePairing(data *binary.PairedData) {
c.updateTachyonAuthToken(data.GetTokenData().GetTachyonAuthToken(), data.GetTokenData().GetTTL())
c.AuthData.Mobile = data.Mobile
c.AuthData.Browser = data.Browser
c.triggerEvent(&events.PairSuccessful{PairedData: data})
reconnectErr := c.Reconnect()
if reconnectErr != nil {
return reconnectErr
err := c.Reconnect()
if err != nil {
c.triggerEvent(&events.ListenFatalError{Error: fmt.Errorf("failed to reconnect after pair success: %w", err)})
}
return nil
}