grammyjs / conversations

Conversational interfaces for grammY.
https://grammy.dev/plugins/conversations
MIT License
53 stars 17 forks source link

Maximum call stack size exceeded when more than one conversations registered #4

Closed x066it closed 2 years ago

x066it commented 2 years ago

When I'm registering more than one conversation I get the error: "Maximum call stack size exceeded" right after triggering the command. When i'm commenting out the second one, the first one is working right.

import { Bot, session } from "grammy";
import { conversations, createConversation } from "@grammyjs/conversations";

const bot = new Bot(token);
bot.use(session({ initial: () => ({}) }));
bot.use(conversations());
bot.use(createConversation(async (_, ctx) => await ctx.reply("First Conversation"), "first"));
bot.use(createConversation(async (_, ctx) => await ctx.reply("Second Conversation"), "second"));
bot.command("first", async (ctx) => await ctx.conversation.enter("first"));
bot.command("second", async (ctx) => await ctx.conversation.enter("second"));
bot.start();
Log

```js Exception in PromiseRejectCallback: /home/chaotik/git/trontrack/node_modules/.pnpm/@grammyjs+conversations@0.6.0_grammy@1.8.3/node_modules/@grammyjs/conversations/out/conversation.js:214 }; ^ RangeError: Maximum call stack size exceeded Exception in PromiseRejectCallback: /home/chaotik/git/trontrack/node_modules/.pnpm/@grammyjs+conversations@0.6.0_grammy@1.8.3/node_modules/@grammyjs/conversations/out/conversation.js:197 await oldEnter(enterId, opts); ^ RangeError: Maximum call stack size exceeded Error in middleware while handling update 580244660 RangeError: Maximum call stack size exceeded at ConversationControls.ctx.conversation.enter (/home/chaotik/git/trontrack/node_modules/.pnpm/@grammyjs+conversations@0.6.0_grammy@1.8.3/node_modules/@grammyjs/conversations/out/conversation.js:193:34) at oldEnter (/home/chaotik/git/trontrack/node_modules/.pnpm/@grammyjs+conversations@0.6.0_grammy@1.8.3/node_modules/@grammyjs/conversations/out/conversation.js:192:57) at ConversationControls.ctx.conversation.enter (/home/chaotik/git/trontrack/node_modules/.pnpm/@grammyjs+conversations@0.6.0_grammy@1.8.3/node_modules/@grammyjs/conversations/out/conversation.js:197:23) at oldEnter (/home/chaotik/git/trontrack/node_modules/.pnpm/@grammyjs+conversations@0.6.0_grammy@1.8.3/node_modules/@grammyjs/conversations/out/conversation.js:192:57) at ConversationControls.ctx.conversation.enter (/home/chaotik/git/trontrack/node_modules/.pnpm/@grammyjs+conversations@0.6.0_grammy@1.8.3/node_modules/@grammyjs/conversations/out/conversation.js:197:23) at oldEnter (/home/chaotik/git/trontrack/node_modules/.pnpm/@grammyjs+conversations@0.6.0_grammy@1.8.3/node_modules/@grammyjs/conversations/out/conversation.js:192:57) at ConversationControls.ctx.conversation.enter (/home/chaotik/git/trontrack/node_modules/.pnpm/@grammyjs+conversations@0.6.0_grammy@1.8.3/node_modules/@grammyjs/conversations/out/conversation.js:197:23) at oldEnter (/home/chaotik/git/trontrack/node_modules/.pnpm/@grammyjs+conversations@0.6.0_grammy@1.8.3/node_modules/@grammyjs/conversations/out/conversation.js:192:57) at ConversationControls.ctx.conversation.enter (/home/chaotik/git/trontrack/node_modules/.pnpm/@grammyjs+conversations@0.6.0_grammy@1.8.3/node_modules/@grammyjs/conversations/out/conversation.js:197:23) at oldEnter (/home/chaotik/git/trontrack/node_modules/.pnpm/@grammyjs+conversations@0.6.0_grammy@1.8.3/node_modules/@grammyjs/conversations/out/conversation.js:192:57) No error handler was set! Set your own error handler with `bot.catch = ...` Stopping bot node:internal/process/promises:279 triggerUncaughtException(err, true /* fromPromise */); ^ RangeError: Maximum call stack size exceeded at ConversationControls.ctx.conversation.enter (/home/chaotik/git/trontrack/node_modules/.pnpm/@grammyjs+conversations@0.6.0_grammy@1.8.3/node_modules/@grammyjs/conversations/out/conversation.js:193:34) at oldEnter (/home/chaotik/git/trontrack/node_modules/.pnpm/@grammyjs+conversations@0.6.0_grammy@1.8.3/node_modules/@grammyjs/conversations/out/conversation.js:192:57) at ConversationControls.ctx.conversation.enter (/home/chaotik/git/trontrack/node_modules/.pnpm/@grammyjs+conversations@0.6.0_grammy@1.8.3/node_modules/@grammyjs/conversations/out/conversation.js:197:23) at oldEnter (/home/chaotik/git/trontrack/node_modules/.pnpm/@grammyjs+conversations@0.6.0_grammy@1.8.3/node_modules/@grammyjs/conversations/out/conversation.js:192:57) at ConversationControls.ctx.conversation.enter (/home/chaotik/git/trontrack/node_modules/.pnpm/@grammyjs+conversations@0.6.0_grammy@1.8.3/node_modules/@grammyjs/conversations/out/conversation.js:197:23) at oldEnter (/home/chaotik/git/trontrack/node_modules/.pnpm/@grammyjs+conversations@0.6.0_grammy@1.8.3/node_modules/@grammyjs/conversations/out/conversation.js:192:57) at ConversationControls.ctx.conversation.enter (/home/chaotik/git/trontrack/node_modules/.pnpm/@grammyjs+conversations@0.6.0_grammy@1.8.3/node_modules/@grammyjs/conversations/out/conversation.js:197:23) at oldEnter (/home/chaotik/git/trontrack/node_modules/.pnpm/@grammyjs+conversations@0.6.0_grammy@1.8.3/node_modules/@grammyjs/conversations/out/conversation.js:192:57) at ConversationControls.ctx.conversation.enter (/home/chaotik/git/trontrack/node_modules/.pnpm/@grammyjs+conversations@0.6.0_grammy@1.8.3/node_modules/@grammyjs/conversations/out/conversation.js:197:23) at oldEnter (/home/chaotik/git/trontrack/node_modules/.pnpm/@grammyjs+conversations@0.6.0_grammy@1.8.3/node_modules/@grammyjs/conversations/out/conversation.js:192:57) { error: RangeError: Maximum call stack size exceeded at ConversationControls.ctx.conversation.enter (/home/chaotik/git/trontrack/node_modules/.pnpm/@grammyjs+conversations@0.6.0_grammy@1.8.3/node_modules/@grammyjs/conversations/out/conversation.js:193:34) at oldEnter (/home/chaotik/git/trontrack/node_modules/.pnpm/@grammyjs+conversations@0.6.0_grammy@1.8.3/node_modules/@grammyjs/conversations/out/conversation.js:192:57) at ConversationControls.ctx.conversation.enter (/home/chaotik/git/trontrack/node_modules/.pnpm/@grammyjs+conversations@0.6.0_grammy@1.8.3/node_modules/@grammyjs/conversations/out/conversation.js:197:23) at oldEnter (/home/chaotik/git/trontrack/node_modules/.pnpm/@grammyjs+conversations@0.6.0_grammy@1.8.3/node_modules/@grammyjs/conversations/out/conversation.js:192:57) at ConversationControls.ctx.conversation.enter (/home/chaotik/git/trontrack/node_modules/.pnpm/@grammyjs+conversations@0.6.0_grammy@1.8.3/node_modules/@grammyjs/conversations/out/conversation.js:197:23) at oldEnter (/home/chaotik/git/trontrack/node_modules/.pnpm/@grammyjs+conversations@0.6.0_grammy@1.8.3/node_modules/@grammyjs/conversations/out/conversation.js:192:57) at ConversationControls.ctx.conversation.enter (/home/chaotik/git/trontrack/node_modules/.pnpm/@grammyjs+conversations@0.6.0_grammy@1.8.3/node_modules/@grammyjs/conversations/out/conversation.js:197:23) at oldEnter (/home/chaotik/git/trontrack/node_modules/.pnpm/@grammyjs+conversations@0.6.0_grammy@1.8.3/node_modules/@grammyjs/conversations/out/conversation.js:192:57) at ConversationControls.ctx.conversation.enter (/home/chaotik/git/trontrack/node_modules/.pnpm/@grammyjs+conversations@0.6.0_grammy@1.8.3/node_modules/@grammyjs/conversations/out/conversation.js:197:23) at oldEnter (/home/chaotik/git/trontrack/node_modules/.pnpm/@grammyjs+conversations@0.6.0_grammy@1.8.3/node_modules/@grammyjs/conversations/out/conversation.js:192:57), ctx: Context { update: { update_id: 580244660, message: { message_id: 335, from: { id: 321274531, is_bot: false, first_name: 'πšŒπš‘πšŠπŸΆπš!πš”', username: 'chaotik', language_code: 'en' }, chat: { id: 321274531, first_name: 'πšŒπš‘πšŠπŸΆπš!πš”', username: 'chaotik', type: 'private' }, date: 1653422914, text: '/first', entities: [ { offset: 0, length: 6, type: 'bot_command' } ] } }, api: Api { raw: {}, config: { use: [Function: use], installedTransformers: [Function: installedTransformers] } }, me: { id: 5335322547, is_bot: true, first_name: 'TronTracker', username: 'tron_tracker_bot', can_join_groups: true, can_read_all_group_messages: false, supports_inline_queries: false }, conversation: ConversationControls { session: {}, enter: [AsyncFunction (anonymous)], [Symbol(conversations)]: { ids: Set(2) { 'first', 'second' } } }, match: '' }, name: 'BotError' } Node.js v17.7.1 ```

KnorpelSenf commented 2 years ago

Thanks for the report! Can you review #5?