I was thinking about how bad I am at reading error messages, and realized
it could be useful to catch the exception and write it in a way that was
easier for me to find the relevant information. So, came up with this proof
of concept:

at_exit do
  error = $!
  if error
    pink, normal, red, green = "\e[35m", "\e[0m", "\e[31m", "\e[32m"

    puts
    puts "#{pink}#{error.class}"
    puts "#{red}#{error.message}#{normal}"
    puts
    puts error.backtrace.map { |line|
      line.sub(%r([^/:]*(?=:)))    { |match| "#{green}#{match}#{normal}" }
          .sub(%r((?<=:)\d+(?=:))) { |match| "#{pink}#{match}#{normal}" }
    }
  end
end


The problem, though, is that $! is still set after this block runs, and so
Ruby still spits out its own exception message afterwards. I don't know how
to stop it from doing this.

I tried setting $!, but it's a read-only variable. Tried raising and
rescuing another exception, which cleared $! for the rest of that at_exit
block, but it was still around in the next at_exit block, and so Ruby still
printed it out. Not sure what else to try.

-Josh