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

[RFC] Suggest to have more detailed error message when doing ContactSelf related operations #1549

Closed
windmemory opened this issue Aug 15, 2018 · 2 comments

Comments

@windmemory
Copy link
Member

Today I found that people are complaining about wechaty logout operation throw errors. I dig into the log and find that, some operations on the ContactSelf was triggered, and since the bot is logged out, error thrown out.

Here is the code in wechaty-puppet that trigger the error:

public selfId (): string {
  log.verbose('Puppet', 'selfId()')

  if (!this.id) {
    throw new Error('not logged in, no this.id yet.')
  }

  return this.id
}

It's totally okay for it throw such error message out, but when using it in wechaty, like this:

public async qrcode (): Promise<string> {
  log.verbose('Contact', 'qrcode()')

  if (this.id !== this.puppet.selfId()) {
    throw new Error('only can get qrcode for the login userself')
  }

  const qrcodeValue = await this.puppet.contactSelfQrcode()
  return qrcodeValue
}

An error with message not logged in, no this.id yet. will be printed out in the console, and to whom are writing bot with wechaty, they will treat this error message as "system message" (which means thrown out by wechaty and should be handled by wechaty)

So I suggest to have a better error message here, to indicate that what operation failed and for what reason that the operation failed. I will submit a PR later to illustrate my proposal.

@huan
Copy link
Member

huan commented Aug 15, 2018

Good catch and nice fix.

Merged!

@windmemory
Copy link
Member Author

Thanks for the merging!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants