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

Use absolute_path of caller_locations to infer engine root #17782

Merged
merged 1 commit into from
Nov 26, 2014
Merged

Use absolute_path of caller_locations to infer engine root #17782

merged 1 commit into from
Nov 26, 2014

Conversation

pointlessone
Copy link
Contributor

According to documentation path only returns file names. On MRI it's not the case but it's likely a bug in MRI. Rubinius tries to implement it according to documentation and Rails get broken on rbx (relevant discussion).

Affected versions of Rails are >= 4.1.0. Would you like me to submit a PR for 4.1 branch, too?

According to documentation `path` only returns file names. On MRI it's
not the case but it's likely a bug in MRI.
rafaelfranca added a commit that referenced this pull request Nov 26, 2014
Use absolute_path of caller_locations to infer engine root
@rafaelfranca rafaelfranca merged commit 1a35f90 into rails:master Nov 26, 2014
rafaelfranca added a commit that referenced this pull request Nov 26, 2014
Use absolute_path of caller_locations to infer engine root
@pointlessone pointlessone deleted the engine-root-master branch November 26, 2014 14:52
@SamSaffron
Copy link
Contributor

something is astray here, this commit breaks discourse, in particular seeing:

/home/sam/.rbenv/versions/2.1.2.discourse/lib/ruby/gems/2.1.0/gems/railties-4.2.0.rc1/lib/rails/engine.rb:360:in `dirname': no implicit conversion of nil into String (TypeError)
    from /home/sam/.rbenv/versions/2.1.2.discourse/lib/ruby/gems/2.1.0/gems/railties-4.2.0.rc1/lib/rails/engine.rb:360:in `inherited'
    from /home/sam/Source/discourse/plugins/poll/plugin.rb:15:in `<module:PollPlugin>'
    from /home/sam/Source/discourse/plugins/poll/plugin.rb:14:in `block in activate!'

after, which is a simple Engine.

after_initialize do
  # Rails Engine for accepting votes.
  module PollPlugin
    class Engine < ::Rails::Engine
      engine_name "poll_plugin"
      isolate_namespace PollPlugin
    end

@SamSaffron
Copy link
Contributor

also .. why should Engine be exploding just cause it can not get a backtrace, seems rather extreme.

@SamSaffron
Copy link
Contributor

This demos the issue:

class A
  def initialize
    instance_eval 'def b; c; end', File.expand_path(__FILE__)
  end

  def c
    puts caller_locations[0].path.nil?
    # false
    puts caller_locations[0].absolute_path.nil?
    # true
   end
end

A.new.b

absolute_path can be nil in some conditions ... so the code above should be:

  caller_locations.map{|location| location.absolute_path || location.path}

@pointlessone
Copy link
Contributor Author

Wouldn't path be nil too in cases when absolute_path is nil?

@SamSaffron
Copy link
Contributor

Nope, run my example

On Monday, December 1, 2014, Alexander Mankuta notifications@github.com
wrote:

Wouldn't path be nil too in cases when absolute_path is nil?


Reply to this email directly or view it on GitHub
#17782 (comment).

@pointlessone
Copy link
Contributor Author

This seem to be a Ruby bug.

According to documentation:

Returns the full file path of this frame.

Same as path, but includes the absolute path.

@SamSaffron
Copy link
Contributor

I think the documentation here needs to be corrected instance_eval can send in whatever name it wants even something that is not a file on the filesystem. absolute_path is attempting to get an actual path.

@ko1 is this a bug ? (see code sample above)

cc @zzak

@SamSaffron
Copy link
Contributor

After discussing this with @ko1 I opened https://bugs.ruby-lang.org/issues/10561 feel free to leave your ideas / comments there @cheba

@brixen
Copy link

brixen commented Dec 4, 2014

@SamSaffron is there an ETA for 4.1.9?

@brixen
Copy link

brixen commented Dec 4, 2014

@SamSaffron also, might it make sense to do a bit of sanity checking here?

File.dirname(call_stack.detect { |p| p !~ %r[railties[\w.-]*/lib/rails|rack[\w.-]*/lib/rack] })

If the resulting path is ".", as was the case here rubinius/rubinius#3223, the behavior of this code is problematic. Considering the issues raised in https://bugs.ruby-lang.org/issues/10561, this Rails code shouldn't unconditionally trust what's coming out of #caller_locations.

@rafaelfranca
Copy link
Member

@brixen next week, maybe in the Tuesday.

@SamSaffron
Copy link
Contributor

@brixen @rafaelfranca agree here, we need to be a bit more protective. also in light of 10561 its possible for a frame to be nil (for injected c frames)

we are probably unlikely to hit this in the real world but worth extra protection.

@brixen
Copy link

brixen commented Dec 20, 2014

@rafaelfranca are there still plans for a 4.1.9? People are having some issues updating to 4.2 and this bug is a pain for a bunch of applications on 4.1.

@rafaelfranca
Copy link
Member

@brixen sure. I was planing to start the release ritual yesterday but life got in the way. I'll try to do it today but Tuesday will be the deadline.

@brixen
Copy link

brixen commented Dec 20, 2014

@rafaelfranca ❤️

yujinakayama added a commit to rspec/rspec-rails that referenced this pull request Dec 27, 2014
The failing scenario was caused by a change in Rails that affects
Rails.root when a Rails::Application is defined in symlinked file.

rails/rails#17782

We've been set up Aruba workspace in each Cucumber scenario with
symlinks, but this tends to behave differently from real files.
Since the example_app project is not so large, we can simply clone it in
each scenario.
yujinakayama added a commit to rspec/rspec-rails that referenced this pull request Dec 27, 2014
The failing scenario was caused by a change in Rails that affects
Rails.root when a Rails::Application is defined in symlinked file.

rails/rails#17782

We've been set up Aruba workspace in each Cucumber scenario with
symlinks, but this tends to behave differently from real files.
Since the example_app project is not so large, we can simply clone it in
each scenario.
yujinakayama added a commit to rspec/rspec-rails that referenced this pull request Dec 27, 2014
The failing scenario was caused by a change in Rails that affects
Rails.root when a Rails::Application is defined in symlinked file.

rails/rails#17782

We've been set up Aruba workspace in each Cucumber scenario with
symlinks, but this tends to behave differently from real files.
Since the example_app project is not so large, we can simply clone it in
each scenario.
@rafaelfranca
Copy link
Member

@brixen just released the first release candidate including this bug fix. I believe next week we will have the final version

@brixen
Copy link

brixen commented Jan 4, 2015

@rafaelfranca many thanks.

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.

None yet

4 participants