Skip to content

Instantly share code, notes, and snippets.

@snipsnipsnip
Created February 26, 2016 15:05
Show Gist options
  • Save snipsnipsnip/52d5108ba052f09ab297 to your computer and use it in GitHub Desktop.
Save snipsnipsnip/52d5108ba052f09ab297 to your computer and use it in GitHub Desktop.
def parse_yaml_with_pretty_error(str)
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