Created
May 31, 2016 08:41
-
-
Save ksss/12cb7c08a41c8de8190e69ecbb6d4315 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ ruby pretty-argumenterror.rb | |
ArgumentError: wrong number of arguments (given 3, expected 2) | |
from: pretty-argumenterror.rb | |
1 | #! /usr/bin/env ruby | |
2 | | |
-> 3 | def foo(a, b) | |
4 | end | |
5 | | |
6 | begin |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/env ruby | |
def foo(a, b) | |
end | |
begin | |
foo(1, 2, 3) | |
rescue => e | |
m = /(?<filename>.*?):(?<lineno>\d+):in\s`(?<method>.*)'/.match(e.backtrace.first) | |
lineno = m["lineno"].to_i - 3 | |
puts "#{e.class}: #{e.message}" | |
puts "from: #{m["filename"]}" | |
IO.foreach(m["filename"]).to_a[lineno, 6].each_with_index do |line, index| | |
n = lineno + index + 1 | |
puts " #{n == m["lineno"].to_i ? "->" : " "} #{n} | #{line}" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment