Ruby error messages

Hi there,

Is the meaning of the ruby error messages defined anywhere? E.g. I get
something like:

NameError: uninitialized constant Blah

and maybe you’ll tell me it’s self explanatory, but it would be nice to
look through a list of errors and read more about what they mean. I
searched the web and asked on ruby-lang irc channel but haven’t turned
up anything yet.

Many thanks in advance.

CHEERS> SAM

Sam J. wrote:

up anything yet.
As far as I know there is no such comprehensive list (note, I may be
wrong
here). But closely looking at the exception stack trace and the code it
points to you usually see what’s wrong very fast.

Kind regards

robert

NameError: uninitialized constant Blah

irb(main):002:0> x = My_case_is_wrong
NameError: uninitialized constant My_case_is_wrong
from (irb):2
irb(main):003:0>

usually,
grep -r Blah you_program_dir
is make clear the situation.

On Nov 24, 2005, at 8:01, Sam J. wrote:

searched the web and asked on ruby-lang irc channel but haven’t turned
up anything yet.

Sounds like a decent wiki page.

What it means is that something Ruby considers a constant is being
used without being initialised, which I suppose is obvious.

The less-obvious bit is “something Ruby considers a constant” which
is “an identifier that starts with an uppercase letter”. All class
and module names, for instance. (Forgive me if that’s a little
amorphous - I don’t have a language grammar to poke through for the
actual definition).

So, for this error, I would look for typos, particularly in
assignment statements (as one poster mentioned), but also in class
definitions - maybe you defined your class as “Balh” when you meant
“Blah”. For particularly tricky cases, you can get a list of
constants via ‘Module.constants’.

matthew smillie.

Find Gruff lib. There is a base.rb file.

In
-------------8<-------8<-------------

  1. begin
  2. require ‘rmagick’
  3. rescue LoadError
  4. require ‘RMagick’ # capitalized on Windows
  5. end

-------------8<-------8<-------------
comment out lines 1-3 and 5. Gruff does not deal good with “requre” on
Win.

Hope this helps you.

Pavel

Thanks Robert and Yuri,

As a ruby newbie I’m finding that I’m getting a little stuck. I’ve been
programming in Java/C like languages for about 15 years, so maybe I’m
just having trouble getting used to the brave new world, so perhaps
you’ll bear with me while I take you through some details.

I really like ruby but I’m finding it hard to get to the bottom of
things when I do get errors.

My current situation involves a module called Gruff. I’ve mailed my
problems to the gruff forums on rubyforge, and we’re working on it
there, however I’d really like to be able to help solve the problem
myself.

I’ve downloaded gruff and rmagick using gems, and I’m trying a gruff
code sample in irb (I previously tried an rmagick sample and that
works):

require ‘rubygems’
require ‘gruff’

g = Gruff::Line.new

require ‘rubygems’ returns a fail, and require ‘gruff’ gives an error,
but I can get it to just return false if I comment out the relevant line
of code in the gruff source.

Anyhow, when I type g = Gruff::Line.new I get the this error:

NameError: uninitialized constant Gruff

which I presume is telling me that we have failed to pull in the gruff
module - adjusting the capitalization is no help:

irb(main):004:0> g = gruff::Line.new
NameError: undefined local variable or method `gruff’ for
#Object:0x2959258
from (irb):4

The thing is I’m stuck as to how to proceed from here - is there some
way for me to interogate the system so I can find out why the require
‘gruff’ is failing?

As I understand it my path is set up fine:

irb(main):005:0> $:
=> [“d:/ruby/lib/ruby/gems/1.8/gems/RMagick-win32-1.9.2-mswin32/bin”,
“d:/ruby/lib/ruby/ge
ms/1.8/gems/RMagick-win32-1.9.2-mswin32/lib”,
“d:/ruby/lib/ruby/gems/1.8/gems/gruff-0.0.6/
bin”, “d:/ruby/lib/ruby/gems/1.8/gems/gruff-0.0.6/lib”,
“d:/ruby/lib/ruby/site_ruby/1.8”,
“d:/ruby/lib/ruby/site_ruby/1.8/i386-msvcrt”,
“d:/ruby/lib/ruby/site_ruby”, “d:/ruby/lib/r
uby/1.8”, “d:/ruby/lib/ruby/1.8/i386-mswin32”, “.”]

i.e. i get all the above after entering the require commands, despite
the fact that they return failures.

hmm, so actually writing all this out helped - as I just fixed the
problem. It seems that I needed to restart irb each time I made
modifications to the source code in order to see the continuing errors
being generated after my modifications.

I was confused beacause after throwing an error once, a repeat call to
require would just return false, without any error message. By
restarting irb and seeing the addtional errors, I commented out a load
of undef_method calls in rmagick.rb and now it all works.

Sometimes you just need to be able to explain these things to someone
:slight_smile:

Many thanks for your input

CHEERS> SAM

Robert K. wrote:

As far as I know there is no such comprehensive list (note, I may be wrong
here). But closely looking at the exception stack trace and the code it
points to you usually see what’s wrong very fast.