Solved

Ruby error

Posted on 2011-09-06
8
450 Views
Last Modified: 2012-05-12
I'm getting the following error message when trying to run a ruby script.  I listed the beginning of the script for reference.  Please help.


<internal:lib/rubygems/custom_require>:29:in `require': no such file to load -- exceptions (LoadError)
        from <internal:lib/rubygems/custom_require>:29:in `require'
        from ./ssh_helpers.rb:6:in `<main>'

-------------------------SCRIPT IS BELOW-------------------------------------

#!/usr/bin/env ruby
require 'rubygems'
require 'open4'
require 'socket'

require 'exceptions'


0
Comment
Question by:johncosentino
  • 4
  • 3
8 Comments
 
LVL 10

Expert Comment

by:Andrew Doades
ID: 36489058
Its this line that's causing the issue:

require 'exceptions'

What are you trying to require? is this a gem or a separate ruby file?

Andrew
0
 
LVL 10

Expert Comment

by:Andrew Doades
ID: 36489064
To Clarify what the error message is, its trying to explain, it doesn't know what 'exceptions' is - it isn't an installed gem, nor is there an 'exceptions.rb' file in the same directory as this script
0
 

Author Comment

by:johncosentino
ID: 36489135
This is a separate ruby file, and I confirmed that the exceptions.rb file is in the same directory as the script in question.
0
 

Author Comment

by:johncosentino
ID: 36490295
So I've found a fix, though I'm still not sure what causes the problem.

if you change the line in the script from require 'exceptions' to require_relative 'exceptions' the problem is resolved.

Apparently the "_relative" tells the script to look in the current directory?  
0
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
LVL 10

Expert Comment

by:Andrew Doades
ID: 36490326
The only thing I can think off, is that ruby is trying to use system call with it being 'exceptions'?
One other thing you could try would be to rename the file to 'my_exceptions.rb' and then
require 'my_exceptions'

By using _relative you're forcing ruby to check the current directory first.

0
 

Author Comment

by:johncosentino
ID: 36490361
This might be a stupid question, but why wouldn't it check the current directory first with just "require"....what does "require" check first?
0
 
LVL 10

Expert Comment

by:Andrew Doades
ID: 36490382
Are you running this script from within the directory its located?

Have you done something like this:
cd /ruby_files/
ruby test.rb

So when you run the ruby file, you're running it from the same directory?

or are you running it like this:
ruby ruby_files/test.rb
0
 
LVL 12

Accepted Solution

by:
JESii earned 500 total points
ID: 36492615
ruby sets up a number of directories that it looks in for locating files that are required.  You can see what that is on your system by typing:
   ruby -e 'puts $:'
(The $: is a global variable that contains the load paths for load / require expressions)

It's kind of a linux convention to not  automatically look in the current directory; this avoids the scenario where someone puts a malicious file in your current directory to has the same name as another command and therefore gets executed when you run that command. That's why in Linux (or Mac Terminal), you have to type:
   ./command_name
to run something from the current directory.

And that's why there's require_relative... to make it easier to access the current directory for loaded or required files.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Ruby on Rails 4 451
Rails 3.0 Routing 3 611
Rails 3 if Check View? 3 289
Using JavaScript to set a scroll bar in Ruby-on-Rails 5 825
I recently rediscovered rails when I needed a holiday project and decided to build a management dashboard for the company where I work.  With it being a project done in my free time, I could focus my time on learning the basics rather than trying to…
In Ruby, Call or invoke a API DLL library is easily via Win32API class, win32-api gem or other gems. For general DLL API call, there are quite a few references, some good tips list below: http://www.rubytips.org/2008/05/13/accessing-windows-api-fro…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now