Created
February 26, 2016 15:05
-
-
Save snipsnipsnip/52d5108ba052f09ab297 to your computer and use it in GitHub Desktop.
def parse_yaml_with_pretty_error(str)
This file contains 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
def parse_yaml_with_pretty_error(str) | |
YAML.load(str) | |
rescue Psych::SyntaxError => e | |
range = e.line - 5..e.line + 5 | |
str.lines[range].zip(range) {|s, n| warn "#{n + 1}: #{s}#{%_#{' ' * (e.column - 1)}^_ if n + 1 == e.line}" } | |
raise | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment