HAML throwing exception on Production but not Development - ruby-on-rails

I've written this HAML:
%script{:src => "http://www.google.com/jsapi?key=mykey" :type => "text/javascript"}
Note the missing comma between :src and :type.
On my Production server (Dreamhost/Linux), I get the following logged exception when I try to view the page:
ActionView::TemplateError (compile error
/home/.kuce/sugarthrill_stage/site/releases/20090927200712/app/views/layouts/standard.haml:6: syntax error, unexpected ':', expecting ')'
haml_temp = _hamlout.push_script(haml_temp, false, false, false, false, false);_hamlout.open_tag("script", false, true, false, false, {}, false, false, nil, nil, :src => "http://www.google.com/jsapi?key=ABQIAAAAynKnt9hv30uxjfbUx9X4DBRU8FW8TmMUFf4GF0BysDPVLHB6-RQwlOJobSWKbilPiM4dB6xk_4JbgQ" :type => "text/javascript");
However, I don't see this error on my Development server (Local OS X, WeBRICK); I see the (correctly-rendered) page.
This is a bit disturbing. Is there any reason that this compilation error would be suppressed on development?

I've got a fix for this that I'll submit as soon as GitHub comes back online. It'll be released as part of Haml 2.2.6, which will be sent out some time today or tomorrow.
Thanks for the bug report!
Edit: This is now fixed in commit f1a6cc9.
Edit 2: This has now been released as part of Haml 2.2.6.

Well that is confusing. I probably can't help you, but I would suggest that if you want to see closer similarities to the way you develop to production systems you should use a server that is considered production ready, and if you can, the same server as your production box.

Related

Brakeman error parse error on value ')' as a result of updated syntax

I have recently installed brakeman and ran the gem on my system. One error it is picking up is in relation to what I believe is a parenthesis.
The line of code it is picking an error up on is:
%p=link_to("Click here", url_for(only_path: false, host: ConfigSetting.get("FORGET_PASSWORD_HOST_PREFIX","localhost"), account_new_passwd_reset_path(key: #guid)))
I have recently updated syntax which required an extra parenthesis after the 'account_new_passwd_path'. I believe this is the issue but I cannot understand why.
The outdated code I had was:
%p=link_to("Click here", url_for(:only_path=>false, :host=>ConfigSetting.get("FORGET_PASSWORD_HOST_PREFIX","localhost"), :controller=>:account, :action=>:new_passwd_reset, :key=>#guid))
As you can see in terms of the routing it is the biggest change around the key #guid area.
Any ideas?
The error I am receiving is 'Error: app/views/passwd_reset_mailer/password_reset.haml:3 :: parse error on value ")" (tRPAREN) Could not parse app/views/passwd_reset_mailer/password_reset.haml'
The problem is the order of arguments. Keyword arguments need to be at the end of the argument list. But then there is another issue that using a url helper together with url_for doesn't really makes sense.
Just change:
%p=link_to(
"Click here",
url_for(
only_path: false,
host: ConfigSetting.get("FORGET_PASSWORD_HOST_PREFIX","localhost"),
account_new_passwd_reset_path(key: #guid)
)
)
to
%p=link_to(
"Click here",
account_new_passwd_reset_url(
host: ConfigSetting.get("FORGET_PASSWORD_HOST_PREFIX","localhost"),
key: #guid
)
)
Please note the _url instead of the _path suffix, which test Rails to build a full URL including the hostname.

"no implicit conversion of nil into String"in the Search Module of Redmine

On the redmine of my company, there is this bug where I get an internal error if I want to search into a project.
Here is the log corresponding to the error:
Processing by SearchController#index as HTML
Parameters: {"utf8"=>"✓", "issues"=>"1", "q"=>"test", "id"=>"sprint"}
Current user: me (id=60)
Completed 500 Internal Server Error in 85.0ms
TypeError (no implicit conversion of nil into String):
lib/plugins/acts_as_searchable/lib/acts_as_searchable.rb:126:in `search'
app/controllers/search_controller.rb:74:in `block in index'
app/controllers/search_controller.rb:73:in `each'
app/controllers/search_controller.rb:73:in `index'
The lines corresponding to the error in the controller are :
if !#tokens.empty?
# no more than 5 tokens to search for
#tokens.slice! 5..-1 if #tokens.size > 5
#results = []
#results_by_type = Hash.new {|h,k| h[k] = 0}
limit = 10
#scope.each do |s|
r, c = s.singularize.camelcase.constantize.search(#tokens, projects_to_search,
:all_words => #all_words,
:titles_only => #titles_only,
:limit => (limit+1),
:offset => offset,
:before => params[:previous].nil?)
#results += r
Here is my config :
Environment:
Redmine version 2.6.9.stable
Ruby version 2.3.0-p0 (2015-12-25) [x86_64-linux]
Rails version 3.2.22
Environment production
Database adapter PostgreSQL
SCM:
Git 1.9.1
Filesystem
Redmine plugins:
no plugin installed
What is interesting is that when I search only one letter, i'm redirected on the search page, but I don't have an internal error.
I'm very new to Redmine developpement and to Ruby, I was just assigned to try to fix this bug. Do any of you have an idea of how to fix it ?
Thanks.
I had the same issue, I was able to fix it by downgrading my ruby & rails version, a working set is :
Rails 3.2.19
Ruby 2.1.4p265
It's look like it's due to a braking change in ruby-2.3.0.
It's really odd. We are using 'Redmine' -2.0.3.1 and we do not have that kind of behaviour.
It seems that "someone" messed up the form linked to the search input. Try to follow that data from when you press enter until it answer you with the 500 error code.
If you can , change the environment to development, this way it will show you more detailed errors.
But I can't help you much more , you didn't provide enough info about the problem.

Rails 4.2 syntax error, unexpected ':', expecting =>

I have two computers that I mainly use to develop my Rails application. While working on Computer 1, I added some bootstrap elements to some inputs. For example:
= f.select :transport_from_state, options_for_select(state_populator, #invoice_ambulance.transport_from_state), { include_blank: true}, { class: 'chosen-select', 'data-placeholder': 'State' }
I added the 'data-placeholder': 'State' and used the 'newer' syntax instead of the old :data-placeholder' => 'State' which works fine. The page works with no errors on Computer 1.
I pulled down on computer 2, and now I am getting an error for every instance of 'data-placeholder'. Here is my error:
syntax error, unexpected ':', expecting =>
...en-select', 'data-placeholder': 'State' }
I can replace it with the old syntax and it works fine. However, I shouldn't have to switch 100 instances of this to a deprecated syntax. I have since bundle installed, bundle updated, and rebuilt the db with no luck.
Computer 1 (works)
ruby 2.2.0p0
Rails 4.2.0
Computer 2 (doesnt work)
ruby 2.2.0preview1
Rails 4.2.0
You need to upgrade Computer 2 to the real Ruby 2.2.0 rather than this beta-ish "preview" version you have. Using quoted symbols with the JavaScript-style trailing colon syntax:
{ 'some string': value }
wasn't valid before Ruby 2.2, the 2.2.0preview1 version you have on Computer 2 apparently doesn't support it.
BTW, there is no old and new syntax, there is an alternate JavaScript-style notation that can be use when the keys in a Hash-literal are some symbols. Whoever told you that the hashrocket is deprecated is, at best, confused.
The "newer" syntax is only for symbols.
{hello: 'world'} is equivalent to {:hello => 'world'} but if your key is a string then you still have to use the "hash rocket" syntax: {'hello' => 'world'}
http://ruby-doc.org/core-2.2.0/Hash.html

Extremely rare haml error

I'm currently trying to deploy an Ruby on Rails 3.0.9 app on a production server. Everything seems to be going fine untill passenger gives an 'We're sorry, but something went wrong.' error upon requesting the website.
The production log shows this error:
Rendered sessions/new.html.haml within layouts/application (5.7ms)
Completed 500 Internal Server Error in 8ms
ActionView::Template::Error (syntax error on line 7, col 7: `'):
2: %h2 Sign in
3: = form_for( :sessions, :url => sessions_path) do |f|
4: .field
5: = f.label :email
6: %br/
7: = f.text_field :email
8: .field
app/views/sessions/new.html.haml:5:in
_app_views_sessions_new_html_haml__1068828667_250539460_0'
app/views/sessions/new.html.haml:3:in
_app_views_sessions_new_html_haml__1068828667_250539460_0'
*Edit: Removing the f.label :email and f.label :password rows makes this error disappear, but this obviously isn't a fix *
Some information about this error:
I develop with aptana on windows
A co-developer who works with this project on a mac, was subject to this error a while ago, but fixed this with some unknown magic with gemsets and rvm.
Bundle list of the production server: http://pastie.org/private/0itpfmbfwqvhpheptqz4ha
Github repository: http://github.com/boersmamarcel/Into-Reality-Portal
I'm deploying with capistrano 2.0 and the bundle recipe for it
A similar error also happens on other views, but somehow this error also points to line 7 of the file, and the error message sometimes shows random strings after
col 7:
I can't manage the global gemset on the production server
Weird fact: If I remove the = f.label :password and = f.label :email rows, the error is gone :s
I would be very grateful if someone could help me with this. We have been working on this error for the whole day and it's driving me nuts.
Thanks
- Bas
Edit: the f.label function seems to be causing the problem. I uploaded a trimmed down version of the view which generated the following error:
http://pastie.org/private/cqqipdvqod3r50x9ciwytq
This application runs succesfully on other mac-based and windows-based computers.
If you copied the above exactly, what is the %br doing with a trailing slash? If you're rending this in HTML (not XHTML) the trailing slash is no longer valid. I don't know if it matters but sometimes the slash character throws off HAML in strange ways for me.
After puzzling with this error for hours and hours, it turned out the I18n gem caused this problem.
I had a unclosed entity in my en.yml which looked like this:
en:
time:
formats:
hourminute: "%H:%M"
date:
Removing the date: part fixed this -in my opinion- very obscure error
Thanks to all the people who used their braincycles on this problem :)!

Puzzled by Rails exception notification system

[update2] One of those problems I solved & can't remember how... :)
[update1] could this be a problem in the model?
PAYPAL_CERT_PEM = File.read("#{Rails.root}/certs/paypal_cert.pem")
APP_CERT_PEM = File.read("#{Rails.root}/certs/app_cert.pem")
APP_KEY_PEM = File.read("#{Rails.root}/certs/app_key.pem")
The page I'm trying to access on my site is the cart page for paypal purchases. Notwithstanding the trouble of getting to this error in the production log amidst an apparent DoS attack, I have no experience working with the exception notifier. What's being called (by my code) is an encryption method in the model for each 'buy now' button. Please help me diagnose the problem.
Rendering .../public/500.html (500 Error)
rendering section "request"
/!\ FAILSAFE /!\ Fri Jan 16 14:59:54 +0000 2009
Status: 500 Internal Server Error
ActionView::TemplateError (protected method `filter_parameters' called for #<PurchaseController:0x7f053d26e280>) on line #3 of vendor/plugins/exception_notification/views/exception_notifier/_request.rhtml:
1: * URL : <%= #request.protocol %><%= #host %><%= #request.request_uri %>
2: * IP address: <%= #request.env["HTTP_X_FORWARDED_FOR"] || #request.env["REMOTE_ADDR"] %>
3: * Parameters: <%= filter_sensitive_post_data_parameters(#request.parameters).inspect %>
4: * Rails root: <%= #rails_root %>
If you are using a "later" version of rails, you probably need to make this change: http://www.floydprice.com/2008/08/exception-notifier-in-rails-21/
The ActionView::TemplateError you've posted is caused by a failure of Exception Notifier in rendering a 500 error page (line #3 of Exception Notifier's own _request.html partial). The more interesting exception is probably the one that came before and caused the 500 in the first place.
Not an answer to your question, but something that will help.
I've recently come to love the Hoptoad gem and site for grouping and reporting exceptions with my app in production. Extremely easy to install and no more trawling through my production logs.
I say switch to this from excpetion notification and see if it helps.

Resources