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

parse error on value ")" (tRPAREN) on Rails ERb files #82

Closed
hakanai opened this issue Feb 7, 2023 · 8 comments
Closed

parse error on value ")" (tRPAREN) on Rails ERb files #82

hakanai opened this issue Feb 7, 2023 · 8 comments
Assignees

Comments

@hakanai
Copy link

hakanai commented Feb 7, 2023

Running flay (as part of metrics_fu), I get errors parsing ERb files some time around updating to Ruby 3.0.

parse error on value ")" (tRPAREN)
skipping app/views/things/_form.html.erb

It seems like a minor issue because it continues to run and finishes without an outright failure, but we have a lot of views so the log gets flooded heavily with these errors.

I have tried also including flay-actionpack in case that fixed the issue, but no, I still get the errors despite having that gem installed as well.

@zenspider
Copy link
Member

any chance you can provide me with a file or fragment that can reproduce your issue?

@hakanai
Copy link
Author

hakanai commented Feb 7, 2023

One example:

<% title('page title') %>

<%= form_for(@thing) do |f| %>
  <%= f.error_messages(class: 'error') %>

  (omitting further form stuff)
<% end %>

And the error/warning comes out on the line with the form_for(@thing).

My impression was that it's happening on all our pages, but perhaps it's only happening on forms. It's just that the majority of pages do contain forms, because of filters and the like.

@zenspider
Copy link
Member

Ah. That's not valid ERB. The = needs to be removed from your form_for block.

Generic example:

9989 % ruby -rerubi -e 'puts Erubi::Engine.new("<%= x.each do %>42<% end %>").src' | ruby -cw
-:1: syntax error, unexpected ')'
...ring.new; _buf << ( x.each do ).to_s; _buf << '42'.freeze; e...
-:1: syntax error, unexpected `end', expecting ')'
....to_s; _buf << '42'.freeze; end ;
-:2: syntax error, unexpected end-of-input
_buf.to_s
-: compile error (SyntaxError)

vs

9990 % ruby -rerubi -e 'puts Erubi::Engine.new("<% x.each do %>42<% end %>").src' | ruby -cw
Syntax OK

@zenspider zenspider self-assigned this Feb 8, 2023
@hakanai
Copy link
Author

hakanai commented Feb 8, 2023

Is this also invalid ERB? https://apidock.com/rails/ActionView/Helpers/FormHelper/form_for

<%= form_for :person do |f| %>
  First name: <%= f.text_field :first_name %><br />
  Last name : <%= f.text_field :last_name %><br />
  Biography : <%= f.text_area :biography %><br />
  Admin?    : <%= f.check_box :admin %><br />
  <%= f.submit %>
<% end %>

Also, the application itself runs and passes all tests... so it's just flay as far as I can tell, and nobody else has issues with it.

Going through the history for the form_for docs, it looks like the equals sign was added for Rails 3.0.0, and was absent in older versions.

Also if I remove the '=', I just get no output. This makes perfect sense, because the '=' is what indicated that it should output. :(

@zenspider
Copy link
Member

zenspider commented Feb 9, 2023

Yes:

% ruby -rerubi -e 'puts Erubi::Engine.new(File.read ARGV.shift).src' bug82.erb
_buf = ::String.new; _buf << ( form_for :person do |f| ).to_s; _buf << '
'.freeze; _buf << '  First name: '.freeze; _buf << ( f.text_field :first_name ).to_s; _buf << '<br />
  Last name : '.freeze; _buf << ( f.text_field :last_name ).to_s; _buf << '<br />
  Biography : '.freeze; _buf << ( f.text_area :biography ).to_s; _buf << '<br />
  Admin?    : '.freeze; _buf << ( f.check_box :admin ).to_s; _buf << '<br />
  '.freeze; _buf << ( f.submit ).to_s; _buf << '
'.freeze; end 
 _buf << '
'.freeze;
_buf.to_s

looks like there's a special form for it: https://github.com/jeremyevans/erubi#capturing-

ETA: buuuut that special form requires me to switch the Engine instantiated, so it won't currently work.

@hakanai
Copy link
Author

hakanai commented Feb 9, 2023

Right, so I gather flay-actionpack exists specifically to use Rails' ERB parser instead of the Ruby one when processing ERB.
Only problem is, having flay-actionpack loaded doesn't necessarily work -

What happens on my machine is, flay loads flay-actionpack's plugin file first, then after it, loads its own one and replaces the process_erb method again. So whatever flay-actionpack does gets undone immediately after.

It seems like this happens in some arbitrary order. It might be based on LOAD_PATH but it doesn't match the order gems are specified in the Gemfile...

I think the only way I'm getting this to work is if there were some way to remove the default erb plugin.

@piacsek
Copy link

piacsek commented Jun 23, 2023

I think the only way I'm getting this to work is if there were some way to remove the default erb plugin.

You can use a .flayignore file to exclude ERB files:

$ cat .flayignore
# ERB parsing is currently broken -> https://github.com/seattlerb/flay/issues/82
./**/*.erb

CC @hakanai

@zenspider
Copy link
Member

This is fixed

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

No branches or pull requests

3 participants