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

remark(null) doesn't work #130

Closed
zfben opened this issue Dec 10, 2016 · 9 comments
Closed

remark(null) doesn't work #130

zfben opened this issue Dec 10, 2016 · 9 comments
Assignees
Labels

Comments

@zfben
Copy link

zfben commented Dec 10, 2016

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

  1. Wechaty version: #git[b1fbeee Merge branch 'master' into test]
  2. Darwin x64 version 16.1.0 memory 27/8192 MB
  3. Docker: false
  4. Node version: v7.2.0

Expected behavior

contact.remark(null) to clear remark.

Actual behavior

WARN PuppetWebBrowser executeAsync() exception: javascript error: Cannot read property 'replace' of null
JavaScript stack:
TypeError: Cannot read p
WARN PuppetWebBridge executeAsync() exception: javascript error: Cannot read property 'replace' of null
JavaScript stack:
TypeError: Cannot read property 'replace' of null
    at Object.formatHTMLToSend (https://res.wx.qq.com/zh_CN/htmledition/v2/js/webwxApp31e225.js:4:6941)
    at contactRemarkAsync (<anonymous>:829:34)
    at eval (eval at executeAsyncScript (:329:5), <anonymous>:6:16)
    at eval (eval at executeAsyncScript (:329:5), <anonymous>:11:8)
    at executeAsyncScript (<anonymous>:329:26)
    at <anonymous>:345:29
    at callFunction (<anonymous>:237:33)
    at <anonymous>:247:23
    at <anonymous>:248:3
  (Session info: chrome=55.0.2883.75)
  (Driver info: chromedriver=2.25.426935 (820a95b0b81d33e42712f9198c215f703412e1a1),platform=Mac OS X 10.12.1 x86_64)

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

if (contact.remark() !== null) {
      await contact.remark(null)
      await contact.refresh()
      log.info('Bot', 'Clear remark: %s', contact.remark())
    }

Paste the full output logs here with WECHATY_LOG=silly set

SILL Contact remark()
VERB PuppetWebBridge proxyWechaty(contactRemarkAsync, @8b743e950927b28834ecec790d655f8a1bf491b6ab75fb6eb2c9271fde59a46f, )
SILL PuppetWebBridge execute()
SILL PuppetWebBrowser Browser.execute("return typeof WechatyBro === "undefined"")
SILL StateMonitor Browser:target() - open
SILL StateMonitor Browser:current() - open
SILL PuppetWebBrowser Browser.executeAsync( const callback = arguments[arguments.length - 1]
      const isAsync = (typeof )
SILL StateMonitor Browser:target() - open
SILL StateMonitor Browser:current() - open
WARN PuppetWebBrowser executeAsync() exception: javascript error: Cannot read property 'replace' of null
JavaScript stack:
TypeError: Cannot read p
WARN PuppetWebBridge executeAsync() exception: javascript error: Cannot read property 'replace' of null
JavaScript stack:
TypeError: Cannot read property 'replace' of null
    at Object.formatHTMLToSend (https://res.wx.qq.com/zh_CN/htmledition/v2/js/webwxApp31e225.js:4:6941)
    at contactRemarkAsync (<anonymous>:829:34)
    at eval (eval at executeAsyncScript (:329:5), <anonymous>:6:16)
    at eval (eval at executeAsyncScript (:329:5), <anonymous>:11:8)
    at executeAsyncScript (<anonymous>:329:26)
    at <anonymous>:345:29
    at callFunction (<anonymous>:237:33)
    at <anonymous>:247:23
    at <anonymous>:248:3
  (Session info: chrome=55.0.2883.75)
  (Driver info: chromedriver=2.25.426935 (820a95b0b81d33e42712f9198c215f703412e1a1),platform=Mac OS X 10.12.1 x86_64)
VERB PuppetWebBridge proxyWechaty(contactRemarkAsync, @8b743e950927b28834ecec790d655f8a1bf491b6ab75fb6eb2c9271fde59a46f, )
WARN PuppetWebBridge proxyWechaty() exception: javascript error: Cannot read property 'replace' of null
JavaScript stack:
TypeError: Cannot read property 'replace' of null
    at Object.formatHTMLToSend (https://res.wx.qq.com/zh_CN/htmledition/v2/js/webwxApp31e225.js:4:6941)
    at contactRemarkAsync (<anonymous>:829:34)
    at eval (eval at executeAsyncScript (:329:5), <anonymous>:6:16)
    at eval (eval at executeAsyncScript (:329:5), <anonymous>:11:8)
    at executeAsyncScript (<anonymous>:329:26)
    at <anonymous>:345:29
    at callFunction (<anonymous>:237:33)
    at <anonymous>:247:23
    at <anonymous>:248:3
  (Session info: chrome=55.0.2883.75)
  (Driver info: chromedriver=2.25.426935 (820a95b0b81d33e42712f9198c215f703412e1a1),platform=Mac OS X 10.12.1 x86_64)
@huan huan self-assigned this Dec 10, 2016
@huan huan added the bug label Dec 10, 2016
huan added a commit that referenced this issue Dec 10, 2016
huan added a commit that referenced this issue Dec 10, 2016
@huan
Copy link
Member

huan commented Dec 10, 2016

Good catch.

Just had a commit for it, please let me know if it fixed this bug, thanks!

@zfben
Copy link
Author

zfben commented Dec 12, 2016

@zixia js error is fixed, but remark is not truly cleared.

my code is:

log.info('Bot', 'Contact: %s: %s', contact.weixin(), contact.remark())

if (contact.remark() !== null) {
      await contact.remark(null)
      await contact.refresh()
      log.info('Bot', 'Clear remark: %s', contact.remark())
    }

output is:

INFO Bot Contact: tobenb520: A#拒绝1# Carpediem
INFO Bot Clear remark: A#拒绝1# Carpediem

the user's remark does not be cleared.

@huan
Copy link
Member

huan commented Dec 12, 2016

@zfben

  1. Could you change your code to check the return value of remark()?
  const ret = await contact.remark(null)
  if (ret) { 
    console.log('ok!')
  } else {
    console.error('fail!') 
  }
  1. Please post the log with WECHATY_LOG=SILLY

  2. After this commit, now remark(null) is equal to remark(''). I remember @lijiarui can clear the remark by remark('') so it should work by remark(null) now, could @lijiarui help me to confirm that?

Thanks.

@lijiarui
Copy link
Member

well.... I tried again, exception disappear...
but failed again
I can change remark by remark('') but cannot by remark(null)

silly log as follows:

SILL Contact remark()
VERB PuppetWebBridge proxyWechaty(contactRemarkAsync, @c379eff781a7d1f8ed7eb8fbb12bbd78, )
SILL PuppetWebBridge execute()
SILL PuppetWebBrowser Browser.execute("return typeof WechatyBro === "undefined"")
SILL StateMonitor Browser:target() - open
SILL StateMonitor Browser:current() - open
SILL PuppetWebBrowser Browser.executeAsync( const callback = arguments[arguments.length - 1]
      const isAsync = (typeof )
SILL StateMonitor Browser:target() - open
SILL StateMonitor Browser:current() - open
WARN PuppetWebBrowser executeAsync() exception: javascript error: Cannot read property 'replace' of null
JavaScript stack:
TypeError: Cannot read p
WARN PuppetWebBridge executeAsync() exception: javascript error: Cannot read property 'replace' of null
JavaScript stack:
TypeError: Cannot read property 'replace' of null
    at Object.formatHTMLToSend (https://res.wx.qq.com/zh_CN/htmledition/v2/js/webwxApp31e225.js:4:6941)
    at contactRemarkAsync (<anonymous>:829:34)
    at eval (eval at executeAsyncScript (:329:5), <anonymous>:6:16)
    at eval (eval at executeAsyncScript (:329:5), <anonymous>:11:8)
    at executeAsyncScript (<anonymous>:329:26)
    at <anonymous>:345:29
    at callFunction (<anonymous>:237:33)
    at <anonymous>:247:23
    at <anonymous>:248:3
  (Session info: chrome=54.0.2840.98)
  (Driver info: chromedriver=2.25.426935 (820a95b0b81d33e42712f9198c215f703412e1a1),platform=Mac OS X 10.10.5 x86_64)
VERB PuppetWebBridge proxyWechaty(contactRemarkAsync, @c379eff781a7d1f8ed7eb8fbb12bbd78, )
WARN PuppetWebBridge proxyWechaty() exception: javascript error: Cannot read property 'replace' of null
JavaScript stack:
TypeError: Cannot read property 'replace' of null
    at Object.formatHTMLToSend (https://res.wx.qq.com/zh_CN/htmledition/v2/js/webwxApp31e225.js:4:6941)
    at contactRemarkAsync (<anonymous>:829:34)
    at eval (eval at executeAsyncScript (:329:5), <anonymous>:6:16)
    at eval (eval at executeAsyncScript (:329:5), <anonymous>:11:8)
    at executeAsyncScript (<anonymous>:329:26)
    at <anonymous>:345:29
    at callFunction (<anonymous>:237:33)
    at <anonymous>:247:23
    at <anonymous>:248:3
  (Session info: chrome=54.0.2840.98)
  (Driver info: chromedriver=2.25.426935 (820a95b0b81d33e42712f9198c215f703412e1a1),platform=Mac OS X 10.10.5 x86_64)
ERR PuppetWebBridge contactRemarkAsync() exception: javascript error: Cannot read property 'replace' of null
JavaScript stack:
TypeError: Cannot read property 'replace' of null
    at Object.formatHTMLToSend (https://res.wx.qq.com/zh_CN/htmledition/v2/js/webwxApp31e225.js:4:6941)
    at contactRemarkAsync (<anonymous>:829:34)
    at eval (eval at executeAsyncScript (:329:5), <anonymous>:6:16)
    at eval (eval at executeAsyncScript (:329:5), <anonymous>:11:8)
    at executeAsyncScript (<anonymous>:329:26)
    at <anonymous>:345:29
    at callFunction (<anonymous>:237:33)
    at <anonymous>:247:23
    at <anonymous>:248:3
  (Session info: chrome=54.0.2840.98)
  (Driver info: chromedriver=2.25.426935 (820a95b0b81d33e42712f9198c215f703412e1a1),platform=Mac OS X 10.10.5 x86_64)
WARN PuppetWeb contactRemark(@c379eff781a7d1f8ed7eb8fbb12bbd78, null) rejected: javascript error: Cannot read property 'replace' of null
JavaScript stack:
TypeError: Cannot read property 'replace' of null
    at Object.formatHTMLToSend (https://res.wx.qq.com/zh_CN/htmledition/v2/js/webwxApp31e225.js:4:6941)
    at contactRemarkAsync (<anonymous>:829:34)
    at eval (eval at executeAsyncScript (:329:5), <anonymous>:6:16)
    at eval (eval at executeAsyncScript (:329:5), <anonymous>:11:8)
    at executeAsyncScript (<anonymous>:329:26)
    at <anonymous>:345:29
    at callFunction (<anonymous>:237:33)
    at <anonymous>:247:23
    at <anonymous>:248:3
  (Session info: chrome=54.0.2840.98)
  (Driver info: chromedriver=2.25.426935 (820a95b0b81d33e42712f9198c215f703412e1a1),platform=Mac OS X 10.10.5 x86_64)
ERR Contact remark(null) rejected: javascript error: Cannot read property 'replace' of null
JavaScript stack:
TypeError: Cannot read property 'replace' of null
    at Object.formatHTMLToSend (https://res.wx.qq.com/zh_CN/htmledition/v2/js/webwxApp31e225.js:4:6941)
    at contactRemarkAsync (<anonymous>:829:34)
    at eval (eval at executeAsyncScript (:329:5), <anonymous>:6:16)
    at eval (eval at executeAsyncScript (:329:5), <anonymous>:11:8)
    at executeAsyncScript (<anonymous>:329:26)
    at <anonymous>:345:29
    at callFunction (<anonymous>:237:33)
    at <anonymous>:247:23
    at <anonymous>:248:3
  (Session info: chrome=54.0.2840.98)
  (Driver info: chromedriver=2.25.426935 (820a95b0b81d33e42712f9198c215f703412e1a1),platform=Mac OS X 10.10.5 x86_64)
fail
> wechaty@0.6.52 doctor /Users/lijiarui/Documents/git/wechaty
> ts-node bin/doctor


#### Wechaty Doctor

1. Wechaty version: #git[4543b8f 0.6.52]
2. Darwin x64 version 14.5.0 memory 543/16384 MB
3. Docker: false
4. Node version: v7.0.0

@huan
Copy link
Member

huan commented Dec 12, 2016

@lijiarui Thanks, I will check it later.
@zfben Before this issue be resolved, please use remark('') instead of remark(null) because it would do the same job and @lijiarui had confirmed it worked.

@huan
Copy link
Member

huan commented Dec 12, 2016

@lijiarui Can you tell me how could remark still be null in this function?

@zfben
Copy link
Author

zfben commented Dec 13, 2016

@zixia I have try to use remark(''), but it doesn't work too.

code:

log.info('Bot', 'Contact: %s: %s', contact.weixin(), contact.remark())

    if (contact.remark() !== null) {
      const ret = await contact.remark('')
      if (ret) {
        console.log('ok')
      } else {
        console.error('fail')
      }
      await contact.refresh()
      log.info('Bot', 'Clear remark: %s', contact.remark())
    }

log:

SILL Contact ready()
SILL Contact remark()
INFO Bot Contact: dafu1220: AA#017# 青
SILL Contact remark()
SILL Contact remark()
VERB PuppetWebBridge proxyWechaty(contactRemarkAsync, @93f450cd41b31c0d89db5885cd37ce24b6eb243b8fe19752f0b0f91b0fb15279, )
SILL PuppetWebBridge execute()
SILL PuppetWebBrowser Browser.execute("return typeof WechatyBro === "undefined"")
SILL StateMonitor Browser:target() - open
SILL StateMonitor Browser:current() - open
SILL PuppetWebBrowser Browser.executeAsync( const callback = arguments[arguments.length - 1]
      const isAsync = (typeof )
SILL StateMonitor Browser:target() - open
SILL StateMonitor Browser:current() - open
ok
SILL Contact ready()
SILL Contact get contact via PuppetWeb
SILL PuppetWebBridge getContact() retryPromise: attampt 1/35 time for timeout 306250
VERB PuppetWebBridge proxyWechaty(getContact, @93f450cd41b31c0d89db5885cd37ce24b6eb243b8fe19752f0b0f91b0fb15279)
SILL PuppetWebBridge execute()
SILL PuppetWebBrowser Browser.execute("return typeof WechatyBro === "undefined"")
SILL StateMonitor Browser:target() - open
SILL StateMonitor Browser:current() - open
SILL PuppetWebBridge execute()
SILL PuppetWebBrowser Browser.execute(" const callback = arguments[arguments.length - 1] const isAsync = (typeof  ... ")
SILL StateMonitor Browser:target() - open
SILL StateMonitor Browser:current() - open
SILL Contact contactGetter(@93f450cd41b31c0d89db5885cd37ce24b6eb243b8fe19752f0b0f91b0fb15279) resolved
SILL Contact remark()
INFO Bot Clear remark: AA#017# 青

huan added a commit that referenced this issue Dec 13, 2016
@huan
Copy link
Member

huan commented Dec 13, 2016

Hi @zfben , sorry for the confusing result, I had found the problem finally.

Your code indeed works, the remark should already be cleared if you check on your phone.

The browser & Wechaty still got the old remark value is because my code forgot to refresh some values in the browser, and when you called refresh(), the old values get back.

Should be fixed in my last commit, I had tested with your code without any problem.

Please let me know if it works for you, thanks.

@zfben
Copy link
Author

zfben commented Dec 13, 2016

it works! thx a lot 👍

@zfben zfben closed this as completed Dec 13, 2016
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

3 participants