Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error handler failed to reply text #951

Open
momocow opened this issue Oct 18, 2021 · 1 comment
Open

Error handler failed to reply text #951

momocow opened this issue Oct 18, 2021 · 1 comment
Labels

Comments

@momocow
Copy link

momocow commented Oct 18, 2021

Describe the bug
A clear and concise description of what the bug is.

Using Line platform, replying text in the error handler (aka _error.js) did not actually send replied text to Line following the guide for error handling in Line.

To Reproduce
Steps to reproduce the behavior:

  1. Make the entry action throw an Error. (index.js)
module.exports = async function App (ctx) {
    throw new Error('test');
}
  1. Set up error handler in _error.js.
module.exports = async function handleError(ctx, props) {
  await ctx.replyText('something wrong 😰');
  console.error(props.error);
  console.log(ctx);
};
  1. Trigger the action by saying anything to the bot.
  2. Nothing is replied from the bot, but in the console we can see the error and the context printed.

I found that on the context object, ctx._shouldBatch is still true which will cause all calls to ctx.replyText() buffered.

_isReplied: false,
_replyMessages: [ { type: 'text', text: 'something wrong 😰' } ],
_pushMessages: [],
_shouldBatch: true,
_sendMethod: 'reply'

Expected behavior
A clear and concise description of what you expected to happen.

The bot should reply "something wrong 😰".

Additional context
Add any other context about the problem here.

Since the ctx.handlerDidEnd() was skipped (as the following snippet) while the error happened and also ctx._shouldBatch was still true, the reply was left in the buffer without sending it out.

.then(() => run(handler)(context, {}))
.then(() => {
if (context.handlerDidEnd) {
return context.handlerDidEnd();
}
})
.catch((err) => {
if (errorHandler) {
return run(errorHandler)(context, { error: err });
}
throw err;
})

@momocow
Copy link
Author

momocow commented Oct 18, 2021

By calling manually await ctx.handlerDidEnd() the problem can be fixed. (The bot manages to reply the error.)

module.exports = async function handleError(ctx, props) {
  await ctx.replyText('something wrong 😰');
  console.error(props.error);
  console.log(ctx);
  await ctx.handlerDidEnd?.();
};

@chentsulin chentsulin added the bug label Nov 10, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants