]> git.giacomolli.uk - onechat/blobdiff - telegram.go
Prove direct cancellation during a pending sync
[onechat] / telegram.go
index e3e33c913734b6901f02808f7a9d004fd2aa6f9f..85b0f44d1ed368cfcb340f0aa7f0edcd9fa3e9fc 100644 (file)
@@ -264,7 +264,7 @@ func (b *TelegramBot) send(ctx context.Context) {
 func (b *TelegramBot) poll(ctx context.Context, l *TurnLoop, whatsapp *WhatsApp) error {
        offset, err := telegramLoadOffset(b.offsetPath)
        if err != nil {
 func (b *TelegramBot) poll(ctx context.Context, l *TurnLoop, whatsapp *WhatsApp) error {
        offset, err := telegramLoadOffset(b.offsetPath)
        if err != nil {
-               return err
+               return fmt.Errorf("load Telegram offset: %w", err)
        }
 
        outage := &TelegramOutage{
        }
 
        outage := &TelegramOutage{
@@ -313,7 +313,11 @@ poll:
                                        continue poll
                                }
 
                                        continue poll
                                }
 
-                               return err
+                               if err != nil {
+                                       return fmt.Errorf("handle Telegram update: %w", err)
+                               }
+
+                               return nil
                        }
 
                        imageOutage.End()
                        }
 
                        imageOutage.End()
@@ -323,7 +327,7 @@ poll:
                        offset = update.UpdateID + 1
                        err = telegramSaveOffset(b.offsetPath, offset)
                        if err != nil {
                        offset = update.UpdateID + 1
                        err = telegramSaveOffset(b.offsetPath, offset)
                        if err != nil {
-                               return err
+                               return fmt.Errorf("save Telegram offset: %w", err)
                        }
                }
        }
                        }
                }
        }
@@ -349,7 +353,8 @@ func (b *TelegramBot) next() (Event, bool) {
 // typing shows the typing action once. A failure is not logged, because the
 // next message or poll logs the state of the network.
 func (b *TelegramBot) typing(ctx context.Context) {
 // typing shows the typing action once. A failure is not logged, because the
 // next message or poll logs the state of the network.
 func (b *TelegramBot) typing(ctx context.Context) {
-       _ = b.api.SendTyping(ctx, b.owner)
+       // The next message or poll reports a network failure.
+       b.api.SendTyping(ctx, b.owner) // nolint: errcheck
 }
 
 // post sends event to the chat. A reply goes as rich messages of its Markdown,
 }
 
 // post sends event to the chat. A reply goes as rich messages of its Markdown,
@@ -475,7 +480,7 @@ func (b *TelegramBot) handle(ctx context.Context, l *TurnLoop, whatsapp *WhatsAp
        default:
                _, err := l.Submit(telegramSource, message.Text)
                if err != nil {
        default:
                _, err := l.Submit(telegramSource, message.Text)
                if err != nil {
-                       return err
+                       return fmt.Errorf("submit Telegram text: %w", err)
                }
 
                err = l.Flush(context.WithoutCancel(ctx))
                }
 
                err = l.Flush(context.WithoutCancel(ctx))