GithubHelp home page GithubHelp logo

Comments (4)

fizruk avatar fizruk commented on August 10, 2024

Thank you for reporting this issue! I will look at it closer later this week.

from telegram-bot-simple.

anpryl avatar anpryl commented on August 10, 2024

I think it could be lost exception in https://github.com/fizruk/telegram-bot-simple/blob/master/src/Telegram/Bot/Simple.hs#L119 on request error

from telegram-bot-simple.

fizruk avatar fizruk commented on August 10, 2024

@anpryl yes, there are actually two places in that function where exceptions might ruin things:

res <- getUpdates (GetUpdatesRequest offset Nothing Nothing Nothing)

and

mapM_ handleUpdate updates

Now when I was working on this before I was not concerned with exception handling for some reason.
For now, to fix your issue, you can simply ignore exceptions and try update in the next iteration.

However, I think it would be good to introduce a friendly way to deal with exceptions (or at least report them). The library design basically follows simple MVC like gloss, The Elm Architecture and Miso, and not one of those deals with user exceptions AFAIK (Elm does not even have those).

Perhaps we should merely add a new handler to the Bot definition:

import Control.Monad.Catch

data BotApp model action = BotApp
  { botExceptionHandlers :: [Handler BotM Action]
  , ...
  }

Then we could use it like this (untested):

shieldWith :: [Handler BotM Action] -> ClientM () -> ClientM ()
shieldWith handlers m = runBotM Nothing (BotM (lift m) `catches` handlers)

startPolling :: [Handler BotM Action] -> (Update -> ClientM ()) -> ClientM ()
startPolling handlers handleUpdate = go Nothing
  where
    go lastUpdateId = do
      ...
      res <- getUpdates (GetUpdatesRequest offset Nothing Nothing Nothing)
        `shieldWith` handlers
      ...
      mapM_ (flip runBotM (reader handleUpdate `catches` handlers)) updates
      ...

In the code above I need also to pass generated actions back for processing and probably run handlers in forks. We probably don't want to handle exceptions inside exception handlers. And we probably want to add a catch-all default exception handler to the end of botExceptionHandlers list.

@anpryl what do you think?

from telegram-bot-simple.

anpryl avatar anpryl commented on August 10, 2024

@fizruk I like the idea to have separate exception handlers for handleUpdate.
But I doubt if it needed for getUpdates. I think that getUpdates exceptions should be logged with a subsequent retry. It might be a good idea to add LoggingT to allow library users control logging destination.

from telegram-bot-simple.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.