Skip to content

Conversation

JasLin
Copy link
Contributor

@JasLin JasLin commented Nov 6, 2016

it maybe cause by designing the ConfigSettings as an interface,walkaround it putting the _puppetinstace into global

trying to fix this issue: 'Cannot create an instance of the abstract class 'FriendRequest'
…nterface, work around it putting the _puppetinstace in to global
@JasLin
Copy link
Contributor Author

JasLin commented Nov 6, 2016

ci fail with src/puppet-web/browser.spec.ts[26, 12]: missing whitespace, it's no about the pull requesting code.
https://travis-ci.org/wechaty/wechaty/jobs/173612563#L370-L373

@huan
Copy link
Member

huan commented Nov 6, 2016

Config is a object, and ConfigSettings is the interface defined for Config.

You can have a look at this line in config.ts:
export const Config: ConfigSetting = require('../package.json').wechaty

which can ensure Config is a object inited by require('../package.json').wechaty

So I believe Config._puppetInstance could be use without any problem, change it to global['_puppetInstance'] will change nothing at all?

I had replied your issue and let's discussed over there.

And thanks for the Pull Request!

@JasLin
Copy link
Contributor Author

JasLin commented Nov 6, 2016

it's diffrent :)i had debuged the code with the puppet-web/friend-request,the puppetinstance was lost on event login and messge, i had debug it,and after save the instance to global, everything is ok。

@huan
Copy link
Member

huan commented Nov 6, 2016

Yes, that's the reason why it's weird.

In my case, _puppetInstance only lost in event login. And I had checked all the code, try to find out which part of the code will modify _puppetInstance. The result is there's only two places: the 1st is inside Wechaty.init() and the 2nd is inside Wechaty.quit().

Apparently, in our test code we only call Wechaty.init(). So why the _puppetInstance lost became a puzzle...

Did you test the latest master? (without your modification)

@JasLin
Copy link
Contributor Author

JasLin commented Nov 6, 2016

yes ,i know where to call this mathod, i had checked your code yesterday and debug on it, the code simple ,but i can not found why the instance was lost.

i will test the latest master later:)

@JasLin
Copy link
Contributor Author

JasLin commented Nov 6, 2016

the latest master still had this issue both on the event login and message

onlogin, the error raise as:

INFO Wechaty v0.5.1 initializing...
https://login.weixin.qq.com/qrcode/oaSzzGPkZg==
[201] Scan QR Code in above url to login:
https://login.weixin.qq.com/qrcode/oaSzzGPkZg==
[200] Scan QR Code in above url to login:
INFO Bot 花开半夏 logined
ERR PuppetWebEvent onServerLogin() exception: Error: no puppet instance
Error: no puppet instance
    at Object.puppetInstance (/home/jas/projects/learning/wechat/wechaty-master/src/config.ts:142:13)
    at PuppetWebFriendRequest.FriendRequest (/home/jas/projects/learning/wechat/wechaty-master/src/friend-request.ts:28:17)
    at PuppetWebFriendRequest (/home/jas/projects/learning/wechat/wechaty-master/src/puppet-web/friend-request.ts:38:5)
    at Wechaty.bot.on.user (/home/jas/projects/learning/wechat/wechaty-master/example/ding-dong-bot.ts:50:19)
    at emitOne (events.js:96:13)
    at Wechaty.emit (events.js:188:7)
    at PuppetWeb.puppet.on (/home/jas/projects/learning/wechat/wechaty-master/src/wechaty.ts:239:19)
    at emitOne (events.js:96:13)
    at PuppetWeb.emit (events.js:188:7)
    at PuppetWeb.<anonymous> (/home/jas/projects/learning/wechat/wechaty-master/src/puppet-web/event.ts:312:10)

on message , it raise as:

INFO Wechaty v0.5.1 initializing...
INFO Bot 花开半夏 logined
ERR PuppetWebEvent onServerMessage() exception: Error: no puppet instance
    at Object.puppetInstance (/home/jas/projects/learning/wechat/wechaty-master/src/config.ts:142:13)
    at PuppetWebFriendRequest.FriendRequest (/home/jas/projects/learning/wechat/wechaty-master/src/friend-request.ts:28:17)
    at PuppetWebFriendRequest (/home/jas/projects/learning/wechat/wechaty-master/src/puppet-web/friend-request.ts:38:5)
    at Wechaty.bot.on.on.on.on.on.e (/home/jas/projects/learning/wechat/wechaty-master/example/ding-dong-bot.ts:62:19)
    at emitOne (events.js:96:13)
    at Wechaty.emit (events.js:188:7)
    at PuppetWeb.puppet.on (/home/jas/projects/learning/wechat/wechaty-master/src/wechaty.ts:239:19)
    at emitOne (events.js:96:13)
    at PuppetWeb.emit (events.js:188:7)
    at PuppetWeb.<anonymous> (/home/jas/projects/learning/wechat/wechaty-master/src/puppet-web/event.ts:384:10)

@JasLin
Copy link
Contributor Author

JasLin commented Nov 6, 2016

the coding is fresh from the master ,since i clone it in to a new folder just now.

@huan
Copy link
Member

huan commented Nov 6, 2016

Ok, let's test this PR on cloud9...

@huan huan merged commit 2f47eed into wechaty:master Nov 6, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants