kurtsson / jekyll-multiple-languages-plugin

I18n support for Jekyll and Octopress
MIT License
925 stars 202 forks source link

Encounter Error: `dup': can't dup NilClass (TypeError) #85

Closed yulu closed 5 years ago

yulu commented 7 years ago

Hi,

I am encountering the following error when generating the site:

> jekyll serve --trace
Configuration file: /Users/yulu/Documents/WebProject/src/_config.yml
            Source: /Users/yulu/Documents/WebProject/src
       Destination: /Users/yulu/Documents/WebProject/src/_site
 Incremental build: disabled. Enable with --incremental
      Generating... 
Building site for default language: "en" to: /Users/yulu/Documents/WebProject/src/_site
Loading translation from file /Users/yulu/Documents/WebProject/src/_i18n/en.yml
Building site for language: "cn" to: /Users/yulu/Documents/WebProject/src/_site/cn
Loading translation from file /Users/yulu/Documents/WebProject/src/_i18n/cn.yml
/Users/yulu/.rvm/gems/ruby-2.3.0/gems/jekyll-multiple-languages-plugin-1.5.1/lib/jekyll-multiple-languages-plugin.rb:37:in `dup': can't dup NilClass (TypeError)
    from /Users/yulu/.rvm/gems/ruby-2.3.0/gems/jekyll-multiple-languages-plugin-1.5.1/lib/jekyll-multiple-languages-plugin.rb:37:in `block (2 levels) in <module:Jekyll>'
    from /Users/yulu/.rvm/gems/ruby-2.3.0/gems/jekyll-multiple-languages-plugin-1.5.1/lib/jekyll-multiple-languages-plugin.rb:34:in `delete_if'
    from /Users/yulu/.rvm/gems/ruby-2.3.0/gems/jekyll-multiple-languages-plugin-1.5.1/lib/jekyll-multiple-languages-plugin.rb:34:in `block in <module:Jekyll>'
    from /Users/yulu/.rvm/gems/ruby-2.3.0/gems/jekyll-3.1.1/lib/jekyll/hooks.rb:97:in `block in trigger'
    from /Users/yulu/.rvm/gems/ruby-2.3.0/gems/jekyll-3.1.1/lib/jekyll/hooks.rb:96:in `each'
    from /Users/yulu/.rvm/gems/ruby-2.3.0/gems/jekyll-3.1.1/lib/jekyll/hooks.rb:96:in `trigger'
    from /Users/yulu/.rvm/gems/ruby-2.3.0/gems/jekyll-3.1.1/lib/jekyll/site.rb:184:in `render'
    from /Users/yulu/.rvm/gems/ruby-2.3.0/gems/jekyll-3.1.1/lib/jekyll/site.rb:59:in `process'
    from /Users/yulu/.rvm/gems/ruby-2.3.0/gems/jekyll-multiple-languages-plugin-1.5.1/lib/jekyll-multiple-languages-plugin.rb:125:in `block in process'
    from /Users/yulu/.rvm/gems/ruby-2.3.0/gems/jekyll-multiple-languages-plugin-1.5.1/lib/jekyll-multiple-languages-plugin.rb:116:in `each'
    from /Users/yulu/.rvm/gems/ruby-2.3.0/gems/jekyll-multiple-languages-plugin-1.5.1/lib/jekyll-multiple-languages-plugin.rb:116:in `process'
    from /Users/yulu/.rvm/gems/ruby-2.3.0/gems/jekyll-3.1.1/lib/jekyll/command.rb:26:in `process_site'
    from /Users/yulu/.rvm/gems/ruby-2.3.0/gems/jekyll-3.1.1/lib/jekyll/commands/build.rb:60:in `build'
    from /Users/yulu/.rvm/gems/ruby-2.3.0/gems/jekyll-3.1.1/lib/jekyll/commands/build.rb:33:in `process'
    from /Users/yulu/.rvm/gems/ruby-2.3.0/gems/jekyll-3.1.1/lib/jekyll/commands/serve.rb:34:in `block (2 levels) in init_with_program'
    from /Users/yulu/.rvm/gems/ruby-2.3.0/gems/mercenary-0.3.6/lib/mercenary/command.rb:220:in `block in execute'
    from /Users/yulu/.rvm/gems/ruby-2.3.0/gems/mercenary-0.3.6/lib/mercenary/command.rb:220:in `each'
    from /Users/yulu/.rvm/gems/ruby-2.3.0/gems/mercenary-0.3.6/lib/mercenary/command.rb:220:in `execute'
    from /Users/yulu/.rvm/gems/ruby-2.3.0/gems/mercenary-0.3.6/lib/mercenary/program.rb:42:in `go'
    from /Users/yulu/.rvm/gems/ruby-2.3.0/gems/mercenary-0.3.6/lib/mercenary.rb:19:in `program'
    from /Users/yulu/.rvm/gems/ruby-2.3.0/gems/jekyll-3.1.1/bin/jekyll:13:in `<top (required)>'
    from /Users/yulu/.rvm/gems/ruby-2.3.0/bin/jekyll:23:in `load'
    from /Users/yulu/.rvm/gems/ruby-2.3.0/bin/jekyll:23:in `<main>'
    from /Users/yulu/.rvm/gems/ruby-2.3.0/bin/ruby_executable_hooks:15:in `eval'
    from /Users/yulu/.rvm/gems/ruby-2.3.0/bin/ruby_executable_hooks:15:in `<main>'

It looks like that some static file path is nil. After add the following checking in the plugin, it works:

 33     if default_lang != current_lang
 34       static_files.delete_if do |static_file|
 35 
 36         if static_file.instance_variable_get(:@relative_path).nil?
 37           
 38           # Remove "/" from beginning of static file relative path
 39           static_file_r_path    = static_file.instance_variable_get(:@relative_path).dup
 40           static_file_r_path[0] = ''
 41           
 42           exclude_paths.any? do |exclude_path|
 43             Pathname.new(static_file_r_path).descend do |static_file_path|
 44               break(true) if (Pathname.new(exclude_path) <=> static_file_path) == 0
 45           end
 46         end
 47       end
 48     end

I am wondering why this happens only to my site.

ghost commented 7 years ago

I get the same message "can't dup NilClass (TypeError)". I am using Ruby 2.3.0, selenium, selenium (0.2.11) selenium-webdriver (3.3.0, 2.53.4), win 7 , 64 bit. Firefox 50. Geckodriver v0.16. The problem is only whwn I use firefox. Any Idea how to solve the problem?

yulu commented 7 years ago

@ranj123 see if you can get it work by modifying the plugin following the code snippet I pasted above?

ghost commented 7 years ago

Thank you

I can't see the code snippet you mention in your reply. Can you sen it?

Regards Ranj

On Mon, May 29, 2017 at 4:18 AM, yulu notifications@github.com wrote:

@ranj123 https://github.com/ranj123 see if you can get it work by modifying the plugin following the code snippet I pasted above?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/Anthony-Gaudino/jekyll-multiple-languages-plugin/issues/85#issuecomment-304558752, or mute the thread https://github.com/notifications/unsubscribe-auth/ADT3O4aXIW8NIqK2tp1hWxHm0Kj7vaaeks5r-isNgaJpZM4LUfQN .

yulu commented 7 years ago

@ranj123

 33     if default_lang != current_lang
 34       static_files.delete_if do |static_file|
 35 
 36         if static_file.instance_variable_get(:@relative_path).nil?
 37           
 38           # Remove "/" from beginning of static file relative path
 39           static_file_r_path    = static_file.instance_variable_get(:@relative_path).dup
 40           static_file_r_path[0] = ''
 41           
 42           exclude_paths.any? do |exclude_path|
 43             Pathname.new(static_file_r_path).descend do |static_file_path|
 44               break(true) if (Pathname.new(exclude_path) <=> static_file_path) == 0
 45           end
 46         end
 47       end
 48     end
ghost commented 7 years ago

Thank you

Where should the code be written? In which file?

On 30. maj 2017, at 02.17, yulu notifications@github.com wrote:

@ranj123

33 if default_lang != current_lang 34 static_files.delete_if do |static_file| 35 36 if static_file.instance_variable_get(:@relative_path).nil? 37
38 # Remove "/" from beginning of static file relative path 39 static_file_r_path = static_file.instance_variable_get(:@relative_path).dup 40 static_file_r_path[0] = '' 41
42 exclude_paths.any? do |exclude_path| 43 Pathname.new(static_file_r_path).descend do |static_file_path| 44 break(true) if (Pathname.new(exclude_path) <=> static_file_path) == 0 45 end 46 end 47 end 48 end — You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.