Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve error output on extract_messages failure
The `extract_messages` helper was designed to fail loudly if the input didn't match what was expected by the regex. The goal was to help hook authors debug and catch these issues quickly and easily. However, there are some situations where hook authors did nothing wrong, for example if you are using `rbenv` and on a version of Ruby where a gem hasn't yet been installed (but the shim already exists), you'll get an error like the following: The `rubocop' command exists in these Ruby versions: 1.9.3-p551 2.1.1 2.1.2 2.2.1 2.2.2 2.3.0 jruby-1.7.20 ...which appears like the following in the hook error output: Analyzing with RuboCop..............................[RuboCop] FAILED Hook raised unexpected error Unexpected output: unable to determine line number or type of error/warning for message '' lib/overcommit/hook/pre_commit/base.rb:31:in `block in extract_messages' lib/overcommit/hook/pre_commit/base.rb:28:in `map' lib/overcommit/hook/pre_commit/base.rb:28:in `extract_messages' lib/overcommit/hook/pre_commit/rubo_cop.rb:19:in `run' lib/overcommit/hook/base.rb:45:in `block in run_and_transform' lib/overcommit/utils.rb:259:in `with_environment' lib/overcommit/hook/base.rb:45:in `run_and_transform' lib/overcommit/hook_runner.rb:152:in `run_hook' lib/overcommit/hook_runner.rb:88:in `block in consume' lib/overcommit/hook_runner.rb:85:in `loop' lib/overcommit/hook_runner.rb:85:in `consume' The stacktrace in this case is unsightly and doesn't explain what's actually going on. Fix this by throwing a special class of error and printing the remaining unprocessed output. Fixes #335
- Loading branch information