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

TypeError : Cannot read property 'join' of null #32

Closed
guziks opened this issue May 5, 2014 · 27 comments

Comments

@guziks
Copy link

commented May 5, 2014

My actions

  1. install extention from webstore
  2. check "Allow access to file URLs"
  3. drag test.adoc (anything, even empty) to browser

Result

page with content:

Error
TypeError : Cannot read property 'join' of null

Versions

chrome 34.0.1847.131
asciidoctor-chrome-extension 0.3.0
windows 8.1

@Mogztter

This comment has been minimized.

Copy link
Member

commented May 5, 2014

Hello @guziks, can you check Chrome's encoding settings and enable the JavaScript console (Control -Shift -J) to get the stack trace ?

Thanks

@guziks

This comment has been minimized.

Copy link
Author

commented May 6, 2014

Chrome's encoding is UTF-8 (Automatic checked)
Output of JS console:

Denying load of chrome-extension://iaalpfgpbocpdfblpnhhgllgbdbchmia/js/jquery-2.0.3.min.map.
Resources must be listed in the web_accessible_resources manifest key in order to be loaded by pages outside the extension.
@Mogztter

This comment has been minimized.

Copy link
Member

commented May 6, 2014

The exception is try / catch https://github.com/asciidoctor/asciidoctor-chrome-extension/blob/master/js/renderer.js#L25 so the stack trace is "swallowed".

I will need to create a new version of the extension to add a log.error() as I am unable to reproduce this bug 😢

Would you be OK to manually install this new version ?

Mogztter added a commit to Mogztter/asciidoctor-chrome-extension that referenced this issue May 6, 2014

@Mogztter

This comment has been minimized.

Copy link
Member

commented May 6, 2014

It would be great if you could clone my repository https://github.com/mogztter/asciidoctor-chrome-extension/tree/issue-32 and then install the local copy of the extension https://github.com/mogztter/asciidoctor-chrome-extension/tree/issue-32#installation

git clone https://github.com/Mogztter/asciidoctor-chrome-extension.git
cd asciidoctor-chrome-extension
git checkout issue-32

You should now see the stack trace in the JavaScript console...

@guziks

This comment has been minimized.

Copy link
Author

commented May 7, 2014

Hello! I've intalled issue-32 branch. Here is console output:

Denying load of chrome-extension://bpmfdcamjmaihibgiefiglmepidffdcl/js/jquery-2.0.3.min.map. Resources must be listed in the web_accessible_resources manifest key in order to be loaded by pages outside the extension. README.adoc:1
TypeError: Cannot read property 'join' of null
    at Date.def.$zone (chrome-extension://bpmfdcamjmaihibgiefiglmepidffdcl/js/opal.js:9392:62)
    at chrome-extension://bpmfdcamjmaihibgiefiglmepidffdcl/js/opal.js:9548:28
    at String.replace (native)
    at Date.def.$strftime (chrome-extension://bpmfdcamjmaihibgiefiglmepidffdcl/js/opal.js:9412:21)
    at $Document.def.$initialize.TMP_1 [as $initialize] (chrome-extension://bpmfdcamjmaihibgiefiglmepidffdcl/js/asciidoctor.js:2740:126)
    at OpalClass.def.$new.TMP_2 [as $new] (chrome-extension://bpmfdcamjmaihibgiefiglmepidffdcl/js/opal.js:1550:23)
    at OpalModule.$load (chrome-extension://bpmfdcamjmaihibgiefiglmepidffdcl/js/asciidoctor.js:9375:29)
    at Object.callback (chrome-extension://bpmfdcamjmaihibgiefiglmepidffdcl/js/renderer.js:18:52)
    at Function.target.(anonymous function) (extensions::SafeBuiltins:19:14)
    at safeCallbackApply (extensions::sendRequest:21:15) 
@Mogztter

This comment has been minimized.

Copy link
Member

commented May 7, 2014

Thanks!
The issue seems related to a date format. Could you open the JavaScript console, type new Date(); and post the result ?

You should obtain something like:

new Date();
Wed May 07 2014 10:50:26 GMT+0200 (CEST)

newdate_js_console

@guziks

This comment has been minimized.

Copy link
Author

commented May 7, 2014

new Date();
Wed May 07 2014 11:59:05 GMT+0300 (Финляндия (лето))

I guess, second pair of parentheses is the issue. Some translation for clarification: лето - summer time. I've tried to disable summer time, but second pair of parentheses is still there (this time "(зима)"). So, regular expressions have to match that.

@Mogztter

This comment has been minimized.

Copy link
Member

commented May 7, 2014

I opened an issue opal/opal#539

Mogztter added a commit to Mogztter/asciidoctor-chrome-extension that referenced this issue May 11, 2014

@Mogztter

This comment has been minimized.

Copy link
Member

commented May 11, 2014

@guziks I updated my issue-32 branch with a quick fix that fallback to GMT (when timezone is unknown).
Can you tell me if this fixes the issue ?

You will need to update your clone and reload the extension in chrome://extensions/.

Thanks

@guziks

This comment has been minimized.

Copy link
Author

commented May 11, 2014

Yes, this fixes the issue, now I can view documents. Still have an error output in the console:

Denying load of chrome-extension://bpmfdcamjmaihibgiefiglmepidffdcl/js/jquery-2.0.3.min.map. 
Resources must be listed in the web_accessible_resources manifest key in order to be loaded by pages outside the extension. 
@Mogztter

This comment has been minimized.

Copy link
Member

commented May 11, 2014

This is not a "real error", source map files are only useful for debugging JavaScript but there is no need to add .map files in a Chrome extension.
You can disable source map in Chrome, see http://stackoverflow.com/a/18365316

@guziks

This comment has been minimized.

Copy link
Author

commented May 11, 2014

Ah, I see.

Ok, should we close the issue or wait for opal team to do something with timezones?

@Mogztter

This comment has been minimized.

Copy link
Member

commented May 11, 2014

I think we can close this issue because the Opal team will work on a much better solution. For now I will merge my "quick hack" to fix this issue.

@Mogztter Mogztter closed this in #35 May 11, 2014

Mogztter added a commit that referenced this issue May 11, 2014

Merge pull request #35 from Mogztter/issue-32
Resolves #32, Opal hack to fallback to GMT when timezone is unknown
@stayfool

This comment has been minimized.

Copy link

commented Feb 10, 2017

This problem is still existed, error message:

TypeError: Cannot read property 'join' of null
    at Date.ːzone [as $zone] (chrome-extension://iaalpfgpbocpdfblpnhhgllgbdbchmia/js/vendor/asciidoctor.js:17868:62)
    at chrome-extension://iaalpfgpbocpdfblpnhhgllgbdbchmia/js/vendor/asciidoctor.js:18056:28
    at RegExp.[Symbol.replace] (<anonymous>)
    at String.replace (native)
    at Date.ːstrftime [as $strftime] (chrome-extension://iaalpfgpbocpdfblpnhhgllgbdbchmia/js/vendor/asciidoctor.js:17919:21)
    at $Document.ːinitialize [as $initialize] (chrome-extension://iaalpfgpbocpdfblpnhhgllgbdbchmia/js/vendor/asciidoctor.js:27367:58)
    at singleton_class_alloc.TMP_4 [as $new] (chrome-extension://iaalpfgpbocpdfblpnhhgllgbdbchmia/js/vendor/asciidoctor.js:3146:23)
    at module_constructor.ːload [as $load] (chrome-extension://iaalpfgpbocpdfblpnhhgllgbdbchmia/js/vendor/asciidoctor.js:33226:43)
    at module_constructor.Opal.Asciidoctor.$$class.$$proto.load (chrome-extension://iaalpfgpbocpdfblpnhhgllgbdbchmia/js/vendor/asciidoctor.js:33467:15)
    at updateBody (chrome-extension://iaalpfgpbocpdfblpnhhgllgbdbchmia/js/renderer.js:74:25)

Version

window 10
chrome 56
asciidoctor.js 1.5.5.100

@Mogztter

This comment has been minimized.

Copy link
Member

commented Feb 10, 2017

@stayfool Thanks for reporting.

The code in Opal is now:

    Opal.defn(self, '$zone', TMP_27 = function ːzone() {
      var self = this;

      
      var string = self.toString(),
          result;

      if (string.indexOf('(') == -1) {
        result = string.match(/[A-Z]{3,4}/)[0];
      }
      else {
        result = string.match(/\([^)]+\)/)[0].match(/[A-Z]/g).join('');
      }

      if (result == "GMT" && /(GMT\W*\d{4})/.test(string)) {
        return RegExp.$1;
      }
      else {
        return result;
      }
    
    }, TMP_27.$$arity = 0);

In your case string.match(/\([^)]+\)/)[0].match(/[A-Z]/g) returns null.

I may have to submit my workaround to Opal to fix this issue.

@tequlia2pop

This comment has been minimized.

Copy link

commented Jun 4, 2017

The problem still exists and I have to roll back to use the previous version 1.5.4.111.😅

@Mogztter

This comment has been minimized.

Copy link
Member

commented Jun 4, 2017

Thanks for sharing @tequlia2pop. Could you please confirm that you did have the same error message ? What is your locale ?

@Mogztter Mogztter reopened this Jun 4, 2017

@Mogztter

This comment has been minimized.

Copy link
Member

commented Jun 4, 2017

Ah! I think I found the issue.

The code in Ruby is:

localtime = (attrs['localtime'] ||= begin
  now.strftime '%H:%M:%S %Z'
rescue # Asciidoctor.js fails if timezone string has characters outside basic Latin (see asciidoctor.js#23)
  now.strftime '%H:%M:%S %z'
end)

https://github.com/asciidoctor/asciidoctor/blob/5da225b5db5e2cf5132709075b1071e9e013a578/lib/asciidoctor/document.rb#L423-L427

And in JavaScript:

try {
  localtime = (($writer = ["localtime", now.$strftime("%H:%M:%S %Z")]), $send(attrs, '[]=', Opal.to_a($writer)), $writer[$rb_minus($writer["length"], 1)])
} catch ($err) {
  if (Opal.rescue($err, [Opal.const_get($scopes, 'StandardError', true, true)])) {
    try {
      localtime = (($writer = ["localtime", now.$strftime("%H:%M:%S %z")]), $send(attrs, '[]=', Opal.to_a($writer)), $writer[$rb_minus($writer["length"], 1)])
    } finally { Opal.pop_exception() }
  } else { throw $err; }
};

@mojavelinux As far as I understand, TypeError is not a "StandardError" and thus the exception is thrown...

@Mogztter

This comment has been minimized.

Copy link
Member

commented Jun 4, 2017

Here's a quick way to reproduce this issue with Opal:

.test.rb

now = ::Time.now
begin
  now.strftime '%H:%M:%S %Z'
rescue
  now.strftime '%H:%M:%S %z'
end
bundle exec opal -- test.rb
TZ="/usr/share/zoneinfo/oops" bundle exec opal -- test.rb
TypeError: Cannot read property '0' of null
    at Date.$$zone [as $zone] (/tmp/opal-nodejs-runner-20170604-15468-mw69b9:19305:43)
    at /tmp/opal-nodejs-runner-20170604-15468-mw69b9:19491:28
    at RegExp.[Symbol.replace] (native)
    at String.replace (native)
    at Date.$$strftime [as $strftime] (/tmp/opal-nodejs-runner-20170604-15468-mw69b9:19354:21)
    at /tmp/opal-nodejs-runner-20170604-15468-mw69b9:21159:16
    at Object.<anonymous> (/tmp/opal-nodejs-runner-20170604-15468-mw69b9:21167:3)
    at Module._compile (module.js:571:32)
    at Object.Module._extensions..js (module.js:580:10)
    at Module.load (module.js:488:32)

If the timezone is unknown the date will be something like: Sun Jun 04 2017 08:34:00 GMT+0000 ()

@Mogztter

This comment has been minimized.

Copy link
Member

commented Jun 4, 2017

The following is working:

now = ::Time.now
begin
  now.strftime '%H:%M:%S %Z'
rescue Exception
  now.strftime '%H:%M:%S %z'
end

Not sure if this is working as intended...
@mojavelinux Do you think we should fix Asciidoctor core and rescue Exception (even though it's a bad practice) ?

@Mogztter

This comment has been minimized.

Copy link
Member

commented Jun 4, 2017

I think JavaScript's TypeError should be "map" as Ruby's TypeError.
I've opened an issue on Opal: opal/opal#1675

@noah538

This comment has been minimized.

Copy link

commented Aug 23, 2017

in Opal project: @Mogztter the root cause should be fixed by b7701da and caaa3a2 😉

Could you kindly tell me how to apply 'opal patch' to fix "TypeError : Cannot read property 'join' of null" happens in asciidoctor-chrome-extension, thank you.

@Mogztter

This comment has been minimized.

Copy link
Member

commented Aug 23, 2017

@noah538 What version of asciidoctor-chrome-extension are you using ?

@noah538

This comment has been minimized.

Copy link

commented Aug 30, 2017

My version was direct download the master from github.com ( by 8/23):
Asciidoctor.js Live Preview 1.5.5.101
Render AsciiDoc (.ad, .adoc, .asc, .asciidoc) as HTML inside your browser!
ID: dmhmaknbgaldhckmdgjfnhbihlenhomn
Source: F:\asciidoctor-chrome-extension-master\app

for a simple asciidoc:

= aaa
== bbb
=== ccc

I still have error:

renderer.js:62 TypeError: Cannot read property 'join' of null
    at Date.ːzone [as $zone] (asciidoctor.js:17868)
    at asciidoctor.js:18056
    at RegExp.[Symbol.replace] (<anonymous>)
    at String.replace (<anonymous>)
    at Date.ːstrftime [as $strftime] (asciidoctor.js:17919)
    at $Document.ːinitialize [as $initialize] (asciidoctor.js:27367)
    at singleton_class_alloc.TMP_4 [as $new] (asciidoctor.js:3146)
    at module_constructor.ːload [as $load] (asciidoctor.js:33226)
    at module_constructor.Opal.Asciidoctor.$$class.$$proto.load (asciidoctor.js:33467)
    at updateBody (renderer.js:72)

should I patch some changelist? thank you.

@Mogztter

This comment has been minimized.

Copy link
Member

commented Aug 30, 2017

should I patch some changelist?

@noah538 No, this issue will be fixed once #161 is resolved. But I want to fix asciidoctor/asciidoctor.js#367 first so we can make a Asciidoctor.js 1.5.6 "final" version.

Sorry about that, hopefully a new release of the Chrome extension will be available in the next couple of weeks.

@Mogztter

This comment has been minimized.

Copy link
Member

commented Aug 30, 2017

Having said that, I think you can monkey-patch the extension if you are using master.

In app/js/vendor/asciidoctor.js (line 17868):

-result = string.match(/\([^)]+\)/)[0].match(/[A-Z]/g).join('');
+result = string.match(/\((.+)\)(?:\s|$)/)[1];

@noah538 Let me know if it's working 😉

@noah538

This comment has been minimized.

Copy link

commented Aug 31, 2017

@Mogztter It works like a charm!! 👍 Thank you! 💯

@Mogztter Mogztter added the 🐞 bug label Aug 31, 2017

@Mogztter Mogztter added this to the 1.5.5.102 milestone Oct 24, 2017

@Mogztter Mogztter closed this in e6181ab Oct 24, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
5 participants
You can’t perform that action at this time.