nickthecook / ops

The operations team for your project.
GNU General Public License v3.0
50 stars 1 forks source link

Handle error cases more neatly #12

Closed nickthecook closed 4 years ago

nickthecook commented 4 years ago

Most of the time, if something is not as ops expects (e.g. ops.yml not present, the structure of a yml or json file is not what ops expects, etc.) ops will exit with a stack trace.

For many of these cases, ops should be more defensive and print a helpful error, rather than just let the stack trace rise to the top.

A []: No such method for NilClass error is not very helpful to the user, but Error: expected "actions" section in ops.yml is.

nickthecook commented 4 years ago

Or this little beauty:

$ ops int
File 'ops.yml' does not exist.
Traceback (most recent call last):
    5: from /Users/nick/.gem/ruby/2.6.6/bin/ops:23:in `<main>'
    4: from /Users/nick/.gem/ruby/2.6.6/bin/ops:23:in `load'
    3: from /Users/nick/.gem/ruby/2.6.6/gems/ops_team-0.2.4/bin/ops:8:in `<top (required)>'
    2: from /Users/nick/.gem/ruby/2.6.6/gems/ops_team-0.2.4/lib/ops.rb:36:in `run'
    1: from /Users/nick/.gem/ruby/2.6.6/gems/ops_team-0.2.4/lib/ops.rb:66:in `action'
/Users/nick/.gem/ruby/2.6.6/gems/ops_team-0.2.4/lib/ops.rb:73:in `actions': undefined method `transform_values' for nil:NilClass (NoMethodError)
nickthecook commented 4 years ago

And this li'l beau'y:

$ bin/ops exec
Traceback (most recent call last):
    4: from bin/ops:8:in `<main>'
    3: from /Users/nick/src/ops/lib/ops.rb:32:in `run'
    2: from /Users/nick/src/ops/lib/ops.rb:54:in `run_action'
    1: from /Users/nick/src/ops/lib/builtins/exec.rb:18:in `run'
/Users/nick/src/ops/lib/builtins/exec.rb:18:in `exec': No such file or directory -  (Errno::ENOENT)
$
nickthecook commented 4 years ago

These three errors are handled properly in 0.9.7.