Skip to content

Fix for pull request #11#13

Open
br3nt wants to merge 7 commits intorahult:masterfrom
NextFaze:master
Open

Fix for pull request #11#13
br3nt wants to merge 7 commits intorahult:masterfrom
NextFaze:master

Conversation

@br3nt
Copy link

@br3nt br3nt commented Apr 19, 2017

As per description of pull request #11, this has the following features:

  • This resolves Karo does not handle non-zero exit codes as an error #10.
  • Raise an exception when a system command fails with a non-zero exception.
  • bin/karo should return a non-zero exit status when an exception is rescued.
  • Error messages should be printed on STDERR, not STDOUT.
  • Inform the user when a system interrupt is triggered on STDERR; this emulates the behaviour of most other UNIX commands.

Additionally, my pull request adds:

  • Fix for unexpected return (LocalJumpError) error
  • Removes rescue of Exception. For why this change is necessary see this SO answer
  • Add backtrace to STDERR for unhandled exceptions so user can diagnose errors better
  • Test for non-zero exit status after running cmd. Was checking for nil but should be checking for non-zero value.

Damien Bezborodov and others added 7 commits November 5, 2015 00:39
This resolves rahult#10.

 - Raise an exception when a system command fails with a non-zero
   exception. (This could be a custom exception.)
 - bin/karo should return a non-zero exit status when an exception is
   rescued.
 - Error messages should be printed on STDERR, not STDOUT.
 - Inform the user when a system interrupt is triggered on STDERR; this
   emulates the behaviour of most other UNIX commands.
Commands that fail should return a non-zero exit status.
Was receiving an error:
```
bin/karo:11:in `rescue in <top (required)>': unexpected return (LocalJumpError)
```

Have changed `return 1` to `exit 1`.  The purpose of this line is to exit the program with a non-zero exit status if an unhandled exception is encountered.
This change means the `rescue` is now only for `StandardError` and its subclasses.

For more info about why this change is necessary, see: [This SO answer][1]

[1]: http://stackoverflow.com/a/10048406/848668
The backtrace has been added to the STDERR output so that the user can identify any issues that may have arisen in the karo code base.

A suggested improvement would be to create a custom `KaroException` error class that can be used to handle any known exception cases within the karo codebase.
After running a command, `$?.exitstatus` will be set to the exit status of the last executed process.
If the process finishes without errors,`$?.exitstatus` will be `0`.
For all other values, we will raise an exception.
@rahult
Copy link
Owner

rahult commented May 22, 2017

Nice work @br3nt, can we squash the commits into one before merging?

@br3nt
Copy link
Author

br3nt commented May 24, 2017

@rahult, looks like you can do it at the time of merging... https://help.github.com/articles/about-pull-request-merges/

@rahult
Copy link
Owner

rahult commented May 24, 2017

Thanks @br3nt, this branch has conflicts based on a previous pull request I merged so cannot do it automatically 😉 (would have been nice)

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Karo does not handle non-zero exit codes as an error

3 participants