Module: Typingpool::App::FriendlyExceptions
- Included in:
- CLI
- Defined in:
- lib/typingpool/app/friendlyexceptions.rb
Instance Method Summary collapse
-
#with_friendly_exceptions(name, *input) ⇒ Object
Massages terse exceptions from our model layer into a human-friendly message suitable for an abort message from a command-line script.
Instance Method Details
#with_friendly_exceptions(name, *input) ⇒ Object
Massages terse exceptions from our model layer into a human-friendly message suitable for an abort message from a command-line script.
Params
- name
-
A string used to refer to the input. For example ‘project title’ or ‘–config argument’. Used in the goodbye message.
- *input
-
One or more values. The user input that will cause any exceptions. Used in the goodbye message.
- &block
-
The block to execute and monitor for exceptions. Will be passed [*input].
Errors
Will abort with a friendly message on any exception of the type Typingpool::Error::Argument.
Returns
The return value of &block.
21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/typingpool/app/friendlyexceptions.rb', line 21 def with_friendly_exceptions(name, *input) begin yield(*input) rescue Typingpool::Error::Argument => exception goodbye = "Could not make sense of #{name.to_s} " goodbye += input.map{|input| "'#{input}'" }.join(', ') goodbye += ". #{exception.}" goodbye += '.' unless goodbye.match(/\.$/) abort goodbye end #begin end |