I use Maruku in Rails simply to convert a Markdown file to HTML so I can use it with Nokogiri. (Maybe there's a better solution for that?) That works fine, but I get lots and lots of "Maruku tells you" messages in the log:
___________________________________________________________________________
| Maruku tells you:
+---------------------------------------------------------------------------
| Could not find ref_id = "FIX" for md_link("FIX", nil)
| Available refs are []
+---------------------------------------------------------------------------
That's really confusing and not needed here. Is there a way to silence Maruku so it only warns in the log if there's a real error?
Looking at the source code and documentation, it looks like you can set :on_error to :ignore :
Maruku.new(string, :on_error => :ignore)
It might also silence "real errors", though.
Maybe try rdiscount gem?
I find Maruku too verbose with errors and do not want to have to ignore all error.
Related
for a long time now HAML syntax errors just spits out a generic error message, like this:
Encountered a syntax error while rendering template: check .component.container-xl.my-3.no-p
.component-header
%div.float-end
I'm using the better_errors gem and if I scroll down to #cause, I can see the actual error here:
#<SyntaxError: /USER PATH STUFF ETC/index.html.haml:47: syntax error, unexpected '=' ...:Haml::Util.escape_html_safe((=number_to_human(investment.va... ... ^ >
Is there a way to display the #cause error on top? Maybe I'll fork the gem and customize the UI to accomplish this...
I ended up forking and hacking better_errors to display the error I wanted here:
https://github.com/Swolie/drgn_better_errors
The Original Problem
Changed ruby version (1.9.3 > 1.9.2) and suddenly all coffeescripts started yielding unexpected INDENT.
I've triple-checked for spaces/tabs inconsistency on files, and this is not the issue. When I comment the entire script, the same bug jumps to the next/another coffeescript file.
Tried with coffee-rails versions 3.2.1 and 3.2.2. No success in both.
Anyone to light a lamp?
More Details
I found what causing this, yet I can't understand why it shoud work differently for different Ruby versions. It's a long story, but here it goes.
I use a trick to declare static or dynamic getters and setters to my classes. This is something like:
Function::dynamic = (prop, desc) ->
Object.defineProperty #prototype, prop, desc
Function::static = (prop, desc) ->
Object.defineProperty #, prop, desc
This provides me a way to declare properties like this:
class MyClass
#static 'accessor'
get: -> _accessor
set: (value) -> _acessor = value
I have plenty of this all over my code, but after Ruby downgrade the code structure just stopped working. Now I'll have to add a comma after the method's first parameter. Like:
#static 'accessor',
get: -> (...)
And this is what it was all about. :S
Answer its not longer necessary, but if anyone could explain it... I'd be glad.
This syntax was not allowed "on purpose", if was merely allowed because the compiler refused to generate 'a'(...). ID block is a call
See this issue.
I'm sure this is an easy question but I'm having a hard time figuring out what to Google.
I'm trying to use the library ChunkyPNG.
I added it to my Gemfile and did a bundle install.
bundle list | grep "chunky"
* chunky_png (1.2.5)
So far so good.
I try using it in my controller:
image = ChunkyPNG::Canvas.from_data_url(params[:data]).to_image
(The docs for this method are available here)
It results in the following error:
NameError in MyController#create
uninitialized constant MyController::ChunkyPNG
Why is prepending the controller namespace? I imagine that's what is causing the error.
Otherwise, it means that ChunkyPNG is not install (and it clearly is).
Am I not able to use this gem upfront without writing some sort of rails plugin to wrap around it?
Thanks
EDIT:
Question has been answered, see #apneadiving's comment
In your controller, or somewhere else in the app do:
require 'chunky_png'
We have a fairly large rails application and I have started this output in our unicorn.log:
#:0xc644248>#:0xc644248>#:0xc4f06e4>#:0xc4f06e4>#:0xca481b4>#:0xca481b4>#:0xc53f604>#:0xc53f604>#:0xcd7a60c>#:0xcd7a60c>#:0xc5df2f8>#:0xc5df2f8>#:0xc69fd00>#:0xc69fd00>#:0xc560ae8>#:0xc560ae8>
It seems to me like there probably is a stray Kernel.puts method call somewhere, but I've been searching for hours and can't find it.
Anyone have tips for tracking something like this down?
You could monkey patch puts, and raise an exception when it's called. You could even fine tune that with a regexp match on your output string (which looks like a recursive object dump).
module Kernel
def puts (s)
raise "puts called, check the backtrace for the source" if s =~ /#:[a-z0-9]>*/
end
end
It could also be that it's not a call to puts, but rather #inspect.
Have you checked for display? That's another method that prints stuff out.
You could go over all the files and search for any calls to Kernel.puts, like so:
find -iname "*.rb" | xargs grep -iR 'Kernel.puts'
However, in terms of neatness (and effectiveness), I would probably go for the solution provided by Jeff Paquette.
This is what I use, it's similar to Banang's answer but maybe even simpler. Do a grep from the directory like so:
grep -rn 'puts' .
Sure it searches everything but you can run it in whatever directory you want to limit that. That should give you the file and line number you need. You can fine tune the search criteria as you wish.
I'm upgrading my Rails app to work with Ruby 1.9 and I keep encountering errors like this:
Anonymous modules have no name to be referenced by
/home/foo/.gem/ruby/1.9.1/gems/activesupport-2.3.8/lib/active_support/dependencies.rb:585:in `to_constant_name'
/home/foo/.gem/ruby/1.9.1/gems/activesupport-2.3.8/lib/active_support/dependencies.rb:391:in `qualified_name_for'
/home/foo/.gem/ruby/1.9.1/gems/activesupport-2.3.8/lib/active_support/dependencies.rb:104:in `rescue in const_missing'
/home/foo/.gem/ruby/1.9.1/gems/activesupport-2.3.8/lib/active_support/dependencies.rb:94:in `const_missing'
/home/foo/app/config/environment.rb:66:in `block in <top (required)>'
etc.
Google finds all kinds of hits for this, but each of them pertains to a specific fix for one specific gem or app. None of them explain what the message really means.
What is an "anonymous module"?
Where is this error message coming from? (The Ruby interpreter itself?)
What is different about Ruby 1.9 that causes this? (Rails 2.3.8 with Ruby 1.8.7 does not encounter this.)
What is the general/proper way to fix this error?
Line 66 of environment.rb is the configuration for super_exception_notifier (old version, 2.0.8):
ExceptionNotifier.configure_exception_notifier do |config|
config[:sender_address] = %("Foo" <foo#foo.com>)
config[:exception_recipients] = %w(foo#foo.com)
config[:skip_local_notification] = false
end
From what I can tell, ExceptionNotifier is undefined, and ActiveSupport is trying to magically load it, but fails and then fails again trying to print a nice error message.
An anonymous module is a module that is declared like so:
Fred = Module.new do
def meth1
"hello"
end
def meth2
"bye"
end
end
instead of by using the regular Module mod_name <block> syntax. Since they have no module name, you can't retrieve the module name. to_constant_name is attempting to call desc.name.blank? where desc is an anonymous module (with no name).
This error is coming from the ActiveSupport module, which may indicate a bug in the active_support gem or may indicate that some other piece of code is using ActiveSupport incorrectly. The error message alone doesn't give enough information to identify the culprit (to me at least, someone with more rails experience might be able to provide more insight).
Without knowing the offending code it's also hard to say exactly why this error is popping up with 1.9, or what needs to be done to fix it. Considering that there are a lot of un- and under-maintained gems out there that have not been updated for 1.9 yet, I would suspect that ActiveSupport is not the source of the problem. Upgrade all of your gems that have 1.9-compatible versions, and then try disabling your other gems one at a time (if you can) and see if you still get the error.
If you provide a list of the other gems that you are using, someone else who may have encountered the error before may be able to provide some details.
This may happen if you try to exploit ActiveRecord's internal class and module contexts in the wrong way. I had this error yesterday while working on a gem which extends deep inner workings of ActiveRecord. I finally managed to get around this problem by redesigning my code which exploits the inner contexts. It would be interesting to see the surrounding lines of environment.rb:66 for further analysis.
This may happen when the class name doesn't match the filename, in
my case it was a file named application.rb contaning the ApplicationController
class. Renaming the file to application_controller.rb solved the problem.
When I got this error, it was due to a misspelling while defining a class. If you are getting this error, it may be worth examining your module and class definitions for typos.