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

Compile error when upgrading to 4.1.0 #767

Closed
remko opened this Issue Dec 12, 2015 · 2 comments

Comments

Projects
None yet
2 participants
@remko
Contributor

remko commented Dec 12, 2015

I'm getting a compile error when upgrading from 4.0.0 to 4.1.0rc:

Message:

NoMethodError: undefined method `reps' for nil:NilClass

Compilation stack:

  (empty)

Stack trace:

  0. /Users/remko/.rvm/gems/ruby-2.2.1/gems/nanoc-4.1.0rc1/lib/nanoc/base/views/item_view.rb:79:in `reps'
  1. /Users/remko/.rvm/gems/ruby-2.2.1/gems/nanoc-4.1.0rc1/lib/nanoc/base/views/item_view.rb:35:in `path'
  2. /Users/remko/src/site/Rules:120:in `block in parse'
  3. /Users/remko/.rvm/gems/ruby-2.2.1/gems/nanoc-4.1.0rc1/lib/nanoc/rule_dsl/rule.rb:58:in `instance_exec'
  4. /Users/remko/.rvm/gems/ruby-2.2.1/gems/nanoc-4.1.0rc1/lib/nanoc/rule_dsl/rule.rb:58:in `apply_to'
  5. /Users/remko/.rvm/gems/ruby-2.2.1/gems/nanoc-4.1.0rc1/lib/nanoc/rule_dsl/rule_memory_calculator.rb:67:in `new_rule_memory_for_rep'
  6. /Users/remko/.rvm/gems/ruby-2.2.1/gems/nanoc-4.1.0rc1/lib/nanoc/rule_dsl/rule_memory_calculator.rb:34:in `[]'
  7. /Users/remko/.rvm/gems/ruby-2.2.1/gems/nanoc-4.1.0rc1/lib/nanoc/base/memoization.rb:54:in `block in memoize'
  8. /Users/remko/.rvm/gems/ruby-2.2.1/gems/nanoc-4.1.0rc1/lib/nanoc/rule_dsl/action_provider.rb:35:in `memory_for'
  9. /Users/remko/.rvm/gems/ruby-2.2.1/gems/nanoc-4.1.0rc1/lib/nanoc/base/services/item_rep_r

The rule looks like this:

   compile '/blog/**/*.md', rep: :linked_excerpt do
    filter :rdiscount, extensions: [:smart]
    filter :more_filter, more_url: item.path
   end

It seems to be the item.path triggering the problem. Is this something that isn't allowed anymore?

@ddfreyne

This comment has been minimized.

Show comment
Hide comment
@ddfreyne

ddfreyne Dec 13, 2015

Member

item.path is indeed the cause of the issue.

In the context of a #compile (or #route or #preprocess) block, it is tricky to get hold of the path of the item currently being compiled, because in Nanoc 4.1, the path could be assigned afterwards, e.g. when using the new #write method:

compile '/blog/**/*.md', rep: :linked_excerpt do
  filter :rdiscount, extensions: [:smart]
  filter :more_filter, more_url: item.path
  write item.identifier.without_ext + '/index.html'
end

In this example, you’d be using the path before it’s even known.

This is not a new problem—the fact that the #path method is accessible on an item in Nanoc 4.0 is a bug. Using it this way will likely trip up the dependency tracker, causing items to be unnecessarily recompiled, or not recompiled when they should be.

I’m working on a fix which will make #path (and related methods, such as #compiled_content, which makes even less sense in a compilation rule) inaccessible, i.e. raise a NoMethodError.

In the mean time, the recommended approach would be to pass the item in its entirely to the :more_filter filter:

compile '/blog/**/*.md', rep: :linked_excerpt do
  filter :rdiscount, extensions: [:smart]
  filter :more_filter, more_item: item
end

:more_filter can then itself get the path of the item using params.fetch(:more_item).path.

Member

ddfreyne commented Dec 13, 2015

item.path is indeed the cause of the issue.

In the context of a #compile (or #route or #preprocess) block, it is tricky to get hold of the path of the item currently being compiled, because in Nanoc 4.1, the path could be assigned afterwards, e.g. when using the new #write method:

compile '/blog/**/*.md', rep: :linked_excerpt do
  filter :rdiscount, extensions: [:smart]
  filter :more_filter, more_url: item.path
  write item.identifier.without_ext + '/index.html'
end

In this example, you’d be using the path before it’s even known.

This is not a new problem—the fact that the #path method is accessible on an item in Nanoc 4.0 is a bug. Using it this way will likely trip up the dependency tracker, causing items to be unnecessarily recompiled, or not recompiled when they should be.

I’m working on a fix which will make #path (and related methods, such as #compiled_content, which makes even less sense in a compilation rule) inaccessible, i.e. raise a NoMethodError.

In the mean time, the recommended approach would be to pass the item in its entirely to the :more_filter filter:

compile '/blog/**/*.md', rep: :linked_excerpt do
  filter :rdiscount, extensions: [:smart]
  filter :more_filter, more_item: item
end

:more_filter can then itself get the path of the item using params.fetch(:more_item).path.

@ddfreyne

This comment has been minimized.

Show comment
Hide comment
@ddfreyne

ddfreyne Dec 13, 2015

Member

Underlying issue is fixed in #768. (item.path will now raise an error.)

Member

ddfreyne commented Dec 13, 2015

Underlying issue is fixed in #768. (item.path will now raise an error.)

@ddfreyne ddfreyne closed this Dec 13, 2015

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment