Skip to content

Instantly share code, notes, and snippets.

@gshutler
Created November 2, 2012 09:28
Show Gist options
  • Select an option

  • Save gshutler/3999740 to your computer and use it in GitHub Desktop.

Select an option

Save gshutler/3999740 to your computer and use it in GitHub Desktop.
Exploring Hatchet API design options for passing errors through
# Exploring API design options as it's hard to think of something that's
# aesthetically pleasing that also avoids needless string interpolation.
# Multiple return arguments.
#
# Syntax looks a little weird with the multiple brace types.
log.error { ["Some message", e] }
log.error {[ "Some message", e ]}
# Passing the exception as an optional parameter.
#
# Breaking change and order feels a little backwards.
log.error(e) { "Some message" }
# Params hash.
#
# Double braces is odd and there's a higher chance of typos.
log.error {{ message: "Some message", error: e }}
# Suggestion by @stephenbinns
#
# Non-block method.
log.error "Some message", e
# And if your message is expensive to create and not always logged:
log.error("Some message #{expensive}", e) if log.error?
# Other?
@gshutler
Copy link
Author

gshutler commented Nov 2, 2012

The formatting of the exception into/alongside the message would be the responsiblity of the formatter(s).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment