Navigation Menu

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

[bug]Cannot read property 'getUserName' of undefined #772

Closed
binsee opened this issue Aug 31, 2017 · 10 comments · Fixed by #811
Closed

[bug]Cannot read property 'getUserName' of undefined #772

binsee opened this issue Aug 31, 2017 · 10 comments · Fixed by #811
Labels

Comments

@binsee
Copy link

binsee commented Aug 31, 2017

Provide Your Network Information

Local operating environment
operating system: Win10 x64
Chrome version: chrome 60.0.3112.113 x32
Wechaty version:

tested is bad: 0.8.179 - 0.8.191
tested is ok: 0.8.174 - 0.8.178

Run npm run doctor or wechaty run doctor(for docker user), paste output here

cd example && ts-node ding-dong-bot.ts

> wechaty@0.8.179 doctor E:\CodeWork\fork\wechaty
> npm run check-node-version && ts-node bin/doctor


> wechaty@0.8.179 check-node-version E:\CodeWork\fork\wechaty
> check-node-version --node ">= 6.9"

node: 8.1.4
npm: 5.0.3
yarn: 0.27.5
17:08:52 SILL Brolog WECHATY_LOG set level to silly
17:08:52 INFO Config registering process.on("unhandledRejection") for development/debug
17:08:53 SILL StateSwitch constructor(Wechaty, standby)
17:08:53 VERB Wechaty contructor()
17:08:53 VERB Doctor constructor()
17:08:53 VERB Doctor testTcp()
17:08:53 SILL Doctor testTcp() client connected

  #### Wechaty Doctor

  1. Wechaty version: #git[7c107d9]
  2. Windows_NT x64 version 10.0.15063 memory 8071/16324 MB
  3. Docker: false
  4. Node version: v8.1.4
  5. Tcp IPC TEST: PASS
  6. Chromedriver: Error: spawnSync chromedriver ENOENT

17:08:53 SILL Doctor testTcp() server closed

Expected behavior

After logging out once, exit the program and start again, by reading the demo.wechaty.json file to get the cookie, log in smoothly, and use all the features normally.

Actual behavior

After the start again, the problem is as follows:

16:57:44 SILL PuppetWebBrowser Browser.execute(" const callback = arguments[arguments.length - 1] const isAsync = (typeof  ... ")
16:57:44 SILL StateSwitch Browser:target() is open
16:57:44 SILL StateSwitch Browser:current() is open
16:57:44 VERB PuppetWebEvent onServerLog(login(page refresh))
16:57:44 VERB PuppetWebEvent onServerLogin(page refresh, 0)
16:57:44 ERR PuppetWebEvent onServerLogin() exception: TypeError: Cannot read property 'getUserName' of undefined
TypeError: Cannot read property 'getUserName' of undefined
    at PuppetWeb.<anonymous> (E:\CodeWork\fork\wechaty\src\puppet-web\event.ts:252:36)
    at Generator.next (<anonymous>)
    at E:\CodeWork\fork\wechaty\src\puppet-web\event.ts:7:71
    at Promise (<anonymous>)
    at __awaiter (E:\CodeWork\fork\wechaty\src\puppet-web\event.ts:3:12)
    at PuppetWeb.onServerLogin (E:\CodeWork\fork\wechaty\src\puppet-web\event.ts:203:12)
    at emitOne (events.js:115:13)
    at Server.emit (events.js:210:7)
    at WebSocket.client.on.data (E:\CodeWork\fork\wechaty\src\puppet-web\server.ts:150:12)
    at emitOne (events.js:115:13)
    at WebSocket.emit (events.js:210:7)
    at Receiver._receiver.onmessage (E:\CodeWork\fork\wechaty\node_modules\ws\lib\WebSocket.js:143:47)
    at Receiver.dataMessage (E:\CodeWork\fork\wechaty\node_modules\ws\lib\Receiver.js:389:14)
    at Receiver.getData (E:\CodeWork\fork\wechaty\node_modules\ws\lib\Receiver.js:330:12)
    at Receiver.startLoop (E:\CodeWork\fork\wechaty\node_modules\ws\lib\Receiver.js:165:16)
    at Receiver.add (E:\CodeWork\fork\wechaty\node_modules\ws\lib\Receiver.js:139:10)
    at TLSSocket._ultron.on (E:\CodeWork\fork\wechaty\node_modules\ws\lib\WebSocket.js:139:22)
    at emitOne (events.js:115:13)
    at TLSSocket.emit (events.js:210:7)
    at addChunk (_stream_readable.js:252:12)
    at readableAddChunk (_stream_readable.js:239:11)
    at TLSSocket.Readable.push (_stream_readable.js:197:10)
    at TLSWrap.onread (net.js:589:20)
16:57:44 ERR Config ###########################
16:57:44 ERR Config unhandledRejection: TypeError: Cannot read property 'getUserName' of undefined [object Promise]
16:57:44 ERR Config ###########################
16:57:44 ERR Config unhandledRejection::catch(Cannot read property 'getUserName' of undefined)
Config TypeError: Cannot read property 'getUserName' of undefined
    at PuppetWeb.<anonymous> (E:\CodeWork\fork\wechaty\src\puppet-web\event.ts:252:36)
    at Generator.next (<anonymous>)
    at E:\CodeWork\fork\wechaty\src\puppet-web\event.ts:7:71
    at Promise (<anonymous>)
    at __awaiter (E:\CodeWork\fork\wechaty\src\puppet-web\event.ts:3:12)
    at PuppetWeb.onServerLogin (E:\CodeWork\fork\wechaty\src\puppet-web\event.ts:203:12)
    at emitOne (events.js:115:13)
    at Server.emit (events.js:210:7)
    at WebSocket.client.on.data (E:\CodeWork\fork\wechaty\src\puppet-web\server.ts:150:12)
    at emitOne (events.js:115:13)
    at WebSocket.emit (events.js:210:7)
    at Receiver._receiver.onmessage (E:\CodeWork\fork\wechaty\node_modules\ws\lib\WebSocket.js:143:47)
    at Receiver.dataMessage (E:\CodeWork\fork\wechaty\node_modules\ws\lib\Receiver.js:389:14)
    at Receiver.getData (E:\CodeWork\fork\wechaty\node_modules\ws\lib\Receiver.js:330:12)
    at Receiver.startLoop (E:\CodeWork\fork\wechaty\node_modules\ws\lib\Receiver.js:165:16)
    at Receiver.add (E:\CodeWork\fork\wechaty\node_modules\ws\lib\Receiver.js:139:10)
    at TLSSocket._ultron.on (E:\CodeWork\fork\wechaty\node_modules\ws\lib\WebSocket.js:139:22)
    at emitOne (events.js:115:13)
    at TLSSocket.emit (events.js:210:7)
    at addChunk (_stream_readable.js:252:12)
    at readableAddChunk (_stream_readable.js:239:11)
    at TLSSocket.Readable.push (_stream_readable.js:197:10)
    at TLSWrap.onread (net.js:589:20)
(node:16896) PromiseRejectionHandledWarning: Promise rejection was handled asynchronously (rejection id: 1)


16:57:48 SILL Contact contactGetter(@730ea843713a538f1a4d8df74555fc000c8b4d981c8e26cd8fc93a1c64ac284e) resolved
16:57:48 SILL Message ready()
16:57:48 SILL Contact ready()
16:57:48 SILL Contact ready()
<杉木>:{TEXT}ding
16:57:48 ERR Bot on(message) exception: Error: no user or no from

Steps to reproduce the behavior (and fixes, if any)

  1. Once you log in, close and log in again. (auto login)
  2. Send the message ding to the bot, output ERR Bot on(message) exception: Error: no user or no from and can't send any msg from the bot.

test

0.8.178 and lower versions is no such problem.
0.8.179 - 0.8.191 This problem must occur
Suspect that the problem may be caused by 3f7791e

@huan
Copy link
Member

huan commented Aug 31, 2017

Thanks for catching this!

I'm looking into it now, it seems that the reason causes this exception is because the login event fired before we init the bridge instance, which will cause TypeError: Cannot read property 'getUserName' of undefined according to this line of source code: this.userId = await this.bridge.getUserName()

Just push a fix to master branch, please let me know if it solved this issue.

@huan
Copy link
Member

huan commented Aug 31, 2017

And I noticed that there's a strange message when you run wechaty doctor:

  1. Chromedriver: Error: spawnSync chromedriver ENOENT

It seems you can run Wechaty, with this error message outputted? I feel it's wired.

@huan
Copy link
Member

huan commented Sep 4, 2017

Hi @binsee, had you tried the latest version? If it does not fix this issue, please let me know.

Thanks!

@binsee
Copy link
Author

binsee commented Sep 4, 2017

start again, output:

14:13:55 SILL PuppetWebBridge execute()
14:13:55 SILL PuppetWebBrowser Browser.execute(" const callback = arguments[arguments.length - 1] const isAsync = (typeof  ... ")
14:13:55 SILL StateSwitch Browser:target() is open
14:13:55 SILL StateSwitch Browser:current() is open
14:13:55 VERB PuppetWebEvent onServerLog(login(page refresh))
14:13:55 VERB PuppetWebEvent onServerLogin(page refresh, 0)
14:13:55 VERB PuppetWebEvent onServerLogin() fired before bridge inited. delay for 1 second.
14:13:55 VERB PuppetWebEvent onServerLog(connectSocket())
14:13:55 VERB PuppetWebEvent onServerLog(checkScan() - already login, no more check, and return(only))
14:13:55 SILL PuppetWebEvent onServerDing(heartbeat@browser)
14:13:55 SILL PuppetWebWatchdog onFeed: 60000, HEARTBEAT[heartbeat@browser]
14:13:55 SILL StateSwitch Puppet:target() is live
14:13:55 SILL StateSwitch Puppet:inprocess() is true
14:13:55 SILL StateSwitch Puppet:target() is live
14:13:55 SILL StateSwitch Puppet:inprocess() is true
14:13:55 WARN PuppetWebWatchdog onFeed(type=HEARTBEAT, data=heartbeat@browser, timeout=60000) is disabled because state target:`live` inprocess:`true`
14:13:55 VERB PuppetWebEvent onServerLog(recv ding)
14:13:55 SILL PuppetWebBridge inject() ding success
14:13:55 VERB PuppetWeb initBridge() done
14:13:55 VERB PuppetWebBrowser clickSwitchAccount()
14:13:55 SILL PuppetWebBrowser clickSwitchAccount() button not found: no such element: Unable to locate element: {"method":"link text","selector":"Switch Account"}
  (Session info: chrome=60.0.3112.113)
  (Driver info: chromedriver=2.32.498550 (9dec58e66c31bcc53a9ce3c7226f0c1c5810906a),platform=Windows NT 10.0.15063 x86_64)
14:13:55 VERB StateSwitch Puppet:current(live,true) <- (live,false)
14:13:55 SILL PuppetWebWatchdog onFeed: 120000, HEARTBEAT[inited]
14:13:55 SILL StateSwitch Puppet:target() is live
14:13:55 SILL StateSwitch Puppet:inprocess() is false
14:13:55 VERB PuppetWebWatchdog clearWatchDogTimer() nothing to clear
14:13:55 SILL PuppetWebWatchdog setWatchDogTimer(120000, HEARTBEAT:[inited])
14:13:55 SILL PuppetWebWatchdog monitorScan(HEARTBEAT)
14:13:55 SILL PuppetWebWatchdog autoSaveSession()
14:13:55 VERB PuppetWebWatchdog autoSaveSession() skiped as no this.userId
14:13:55 SILL PuppetWebWatchdog memoryCheck() free: 11703 MB, require: 4 MB
14:13:55 VERB PuppetWeb init() done
14:13:55 VERB StateSwitch Wechaty:current(ready,true) <- (ready,false)
Wechaty exit 99 because of uncaughtException
14:13:56 VERB Wechaty say(Wechaty exit 99 because of uncaughtException )

update:
I did not track the location of the code that caused the exception

@binsee
Copy link
Author

binsee commented Sep 4, 2017

about clickSwitchAccount() button not found: no such element:

html:

<a href="javascript:;" ng-click="qrcodeLogin()" class="button button_default">切换帐号</a>

can use:

// file: src/puppet-web/browser.ts
// clickSwitchAccount()
const button = await this.driver.driver.findElement(By.xpath('//a[@ng-click="qrcodeLogin()"]'))

@huan
Copy link
Member

huan commented Sep 4, 2017

@binsee Yes, I fully agree with you because your implementation can compatible with different language settings.

Could you please send a PR to fix this? Thanks!

BTW: this button is not always there, so it's ok if wechaty can not find this button.

@binsee
Copy link
Author

binsee commented Sep 4, 2017

@zixia ok, see #781

@huan
Copy link
Member

huan commented Sep 16, 2017

I believe this issue should not exist anymore with the latest code because we use the setTimeout to delay and wait for the bridge initialization.

Could you please confirm this? If so, then we will be able to close this issue.

@binsee
Copy link
Author

binsee commented Sep 16, 2017

yes, no reappear.
I will close this issues.

@binsee binsee closed this as completed Sep 16, 2017
@huan
Copy link
Member

huan commented Sep 16, 2017

Great, thanks!

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

Successfully merging a pull request may close this issue.

2 participants