Josh Thompson     about     archive     turing     office hours

Turing Prep appendix: Troubleshooting Errors

Index of this series:

As you run into problems (and others) let me know. I’d like to collect a broad swath of the errors folks run into, and the solutions, so they don’t get too caught up.

Here’s a quick index of what’s in this guide:

Traceback... cannot load such file -- pry

This seems like an intimidating error message at first.

It’s not. The error just says:

Dear user, you’ve asked me to import code to run these tests, but I cannot find the code you require.

The code I was looking for (and cannot find) is called pry

Pry is an amazing tool. You’ll soon come to love it. In the mean time, just install it. It’s a ruby “gem” so you use the gem install <gem_name> command.

In your terminal, run gem install pry and then run the tests again.

Cannot open Atom from the terminal

You may need to install the Atom Shell Commands. Atom makes it super easy to do this:

install shell commands

FSPathMakeRef and a bunch of other stuff

Here’s an error one student saw:

FSPathMakeRef(/Applications/Atom.app) failed with error -36.

Googling around led here: https://github.com/atom/atom/issues/5222

One possible cause was the user’s machine had two instances of Atom.app on it. (In this case, one was in the Downloads folder, the other in Applications. Delete one of them, try again.

gem install pry failing with “you do not have permission”

If you get an error like this:

ERROR:  While executing gem ... (Gem::FilePermissionError)
    You don't have write permissions for the /Library/Ruby/Gems/2.3.0 directory.

Don’t worry. We’ll sort you out. It’ll take some work.

First, lets see which installed version of Ruby your computer is trying to use when you type ruby:

$ which ruby

If you get something that looks like this:

/usr/bin/ruby

We’ll need to fix it. Read on.

If you get something like one of these:

/Users/joshthompson/.rbenv/shims/ruby
/Users/joshthompson/.rvm/rubies/ruby-2.3.3/bin/ruby

You’re in good shape. Stop reading this section. The rest of this fix will not apply to you.

/usr/bin/ruby

This means you’re using the version of Ruby that came installed on your laptop. You shouldn’t be messing with this version of Ruby, so your system isn’t letting you.

To use Ruby safely, you’ll need to install some tool to manage Ruby’s environment. rbenv is the most common tool for this: https://github.com/rbenv/rbenv

You should have [homebrew](https://brew.sh/) on your computer already. If you don’t figure out how to install it.

If you have it, here’s a summary of the instructions for MacOS:

$ brew install rbenv
$ rbenv init

Restart your terminal.

Now, make sure (again) that rbenv is working:

$ rbenv -v

You should get something like rbenv 1.1.2 back.

Next, tell rbenv to install ruby 2.4.1:

$ rbenv install 2.4.1

And then set this version of ruby as the “global” version to use, until you tell it otherwise or a particular project specifies a different version:

$ rbenv global 2.4.1

You can now do gem install pry, and it will install the gem to the 2.4.1 version of Ruby, as managed by rbenv.

undefined method pry

undefined method 'pry' for #Binding:0x0007f8f980d39f8>

When you try to hit a pry in your tests, you might type in something like:

def test_12
  children = ["Sarah", "Owen", "Peter"]
  
  binding.pry # adding a pry
  one_string = children
  assert_equal "Sarah, Owen, Peter", one_string
end

And then you get an error like:

undefined method 'pry' for #Binding:0x0007f8f980d39f8>

The problem is ruby needs the pry gem to be available in the file where you’re trying to use binding.pry. There’s two ways to do this. The cumbersome way, and the easy way:

The cumbersome way: At the top of any file where you want to use binding.pry, add require 'pry'

Like so:

require pry at top of file

This is cumbersome because as you move through Turing, you’ll find yourself working with more and more files, and wanting to use pry in all of them. You’ll be littering the top of every file with require 'pry', and it’ll be annoying.

The easy way: auto-require the pry whenever you add a pry statement

Here’s how you can get a pry statement without adding anything to the top of the file:

require pry in-line

Wahoo!

Hold up, Josh. That’s a lot to type every time I wanna stick a pry in somewhere. How is this the easy way.

Right you are, thoughtful reader. Right you are.

I often feel pretty bad at typing. I make mistakes all the time. The backspace key on my keyboard gets more usage than any other key. So, If I had to type out require 'pry';binding,pry I mean require "pry":bindingpry I mean… well, you get the idea.

We’re going to set up a snippet in atom, so you’ll just type pry and hit the tab key, and you’ll have glorious auto-expansion.

Here’s how:

  1. Go to Atom > Snippets

go to snippets

  1. Paste your fancy new snippet shortcut into the snippets.cson file:
'.source.ruby':
  'require "pry"':
    'prefix': 'pry'
    'body': 'require "pry"; binding.pry'

It should look something like this:

the whole .cson file

What does that all mean? Great question. Heres Atom’s docs on snippets

Now you can type pry and hit the tab key, and it’ll auto-expand into the full snippet.

pry all day

Go forth and pry into everything!

Subscribe via Email

When I write a new post, you'll get an email the next Friday, straight to your inbox.