sipeed/picoclaw · error

failed to create bot handler

Error message

failed to create bot handler: %w

What it means

Returned by TelegramChannel.Start when th.NewBotHandler fails after long polling was already established. This is a library-side wiring failure over the updates channel, not a Telegram API error; Start cleans up by cancelling the context it just created.

Solutions

  1. Restart the channel — handler construction failures are typically transient allocation/wiring issues
  2. Upgrade or inspect the telego handler library version if the failure is persistent
  3. Check the wrapped error for the concrete cause before assuming API problems
Defensive patterns

Strategy: try-catch

When it happens

Trigger: Thrown at pkg/channels/telegram/telegram.go:168 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of sipeed/picoclaw@49183d7e8d (2026-08-15). Data as JSON: /api/errors/33488fd375ab43cf. Report an issue: GitHub.

Appendix: source

Thrown at pkg/channels/telegram/telegram.go:168

}

func (c *TelegramChannel) Start(ctx context.Context) error {
	logger.InfoC("telegram", "Starting Telegram bot (polling mode)...")

	c.ctx, c.cancel = context.WithCancel(ctx)

	updates, err := c.bot.UpdatesViaLongPolling(c.ctx, &telego.GetUpdatesParams{
		Timeout: 30,
	})
	if err != nil {
		c.cancel()
		return fmt.Errorf("failed to start long polling: %w", err)
	}

	bh, err := th.NewBotHandler(c.bot, updates)
	if err != nil {
		c.cancel()
		return fmt.Errorf("failed to create bot handler: %w", err)
	}
	c.bh = bh

	bh.HandleMessage(func(ctx *th.Context, message telego.Message) error {
		return c.handleMessage(ctx, &message)
	}, th.AnyMessage())

	c.SetRunning(true)
	logger.InfoCF("telegram", "Telegram bot connected", map[string]any{
		"username": c.bot.Username(),
	})

	c.startCommandRegistration(c.ctx, commands.BuiltinDefinitions())

	go func() {
		if err = bh.Start(); err != nil {
			logger.ErrorCF("telegram", "Bot handler failed", map[string]any{
				"error": err.Error(),

View on GitHub (pinned to 49183d7e8d)