Project

errorspray

0.0
No commit activity in last 3 years
No release in over 3 years
Makes it easy to append contextual information to error messages
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

 Project Readme

installation

Gemfile:

gem 'errorspray'

running specs

rbenv exec bundle exec rspec spec/errorspray_spec.rb

purpose

This Ruby gem makes it simple to append contextual information to error messages, providing a "semantic backtrace" alongside the normal backtrace.

The raise_append method takes a string and a block, and if all goes well, returns the result of the block:

> raise_append('here goes nothing') { 1 + 2 }
=> 3

However, if an exception occurs in the block, the string is appended to that exception's message:

> raise_append('how could I have foreseen this?') { 1 / 0 }
ZeroDivisionError: divided by 0
	how could I have foreseen this?

This becomes more useful when the error condition is not obvious:

> (0..10).map { |n| raise_append("for input: #{n.inspect}") { 1 / ((2 * n) - 4) } }
ZeroDivisionError: divided by 0
	for input: 2