From 3058ed94abe3842a50c091dc1ad062b88bc9d497 Mon Sep 17 00:00:00 2001 From: Josh Hagins Date: Mon, 4 Jan 2016 17:21:56 -0500 Subject: [PATCH 1/5] Print error message with suggestions if header parse failed --- lib/hbc/cli.rb | 1 + lib/hbc/exceptions.rb | 3 +++ lib/hbc/source/path_base.rb | 2 +- test/cask/dsl_test.rb | 2 +- 4 files changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/hbc/cli.rb b/lib/hbc/cli.rb index 5439fdc339..e78dcfca41 100644 --- a/lib/hbc/cli.rb +++ b/lib/hbc/cli.rb @@ -116,6 +116,7 @@ class Hbc::CLI run_command(command, *rest) rescue Hbc::CaskError, Hbc::CaskSha256MismatchError => e onoe e + puts Hbc::Utils.error_message_with_suggestions if e.is_a?(Hbc::CaskHeaderParseError) $stderr.puts e.backtrace if Hbc.debug exit 1 rescue StandardError, ScriptError, NoMemoryError => e diff --git a/lib/hbc/exceptions.rb b/lib/hbc/exceptions.rb index 58fd1c3af5..d957830e23 100644 --- a/lib/hbc/exceptions.rb +++ b/lib/hbc/exceptions.rb @@ -126,6 +126,9 @@ class Hbc::CaskInvalidError < Hbc::CaskError end end +class Hbc::CaskHeaderParseError < Hbc::CaskInvalidError +end + class Hbc::CaskSha256MissingError < ArgumentError end diff --git a/lib/hbc/source/path_base.rb b/lib/hbc/source/path_base.rb index 7ba75440ea..dd732db10e 100644 --- a/lib/hbc/source/path_base.rb +++ b/lib/hbc/source/path_base.rb @@ -55,7 +55,7 @@ class Hbc::Source::PathBase raise Hbc::CaskInvalidError.new(cask_token, "Bad header line: '#{header_token}' does not match file name") end else - raise Hbc::CaskInvalidError.new(cask_token, "Bad header line: parse failed") + raise Hbc::CaskHeaderParseError.new(cask_token, "Bad header line: parse failed") end # simulate "require" diff --git a/test/cask/dsl_test.rb b/test/cask/dsl_test.rb index 42c06a1899..c6db86cf39 100644 --- a/test/cask/dsl_test.rb +++ b/test/cask/dsl_test.rb @@ -48,7 +48,7 @@ describe Hbc::DSL do it "requires a valid header format" do err = lambda { invalid_cask = Hbc.load('invalid/invalid-header-format') - }.must_raise(Hbc::CaskInvalidError) + }.must_raise(Hbc::CaskHeaderParseError) err.message.must_include 'Bad header line: parse failed' end From 70022ba549a1a2b6dc1a29b00a2fec083fdee7f4 Mon Sep 17 00:00:00 2001 From: Josh Hagins Date: Mon, 4 Jan 2016 17:22:34 -0500 Subject: [PATCH 2/5] Add 'brew uninstall --force brew-cask' to Hbc::Utils::UPDATE_CMD --- lib/hbc/utils.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/hbc/utils.rb b/lib/hbc/utils.rb index d3dc107a20..a25fb23fe7 100644 --- a/lib/hbc/utils.rb +++ b/lib/hbc/utils.rb @@ -6,7 +6,7 @@ require 'stringio' require 'hbc/utils/tty' -UPDATE_CMD = "brew update; brew cleanup; brew cask cleanup" +UPDATE_CMD = "brew uninstall --force brew-cask; brew update; brew cleanup; brew cask cleanup" ISSUES_URL = "https://github.com/caskroom/homebrew-cask#reporting-bugs" # todo: temporary From 205ccc3c3a91b2af9c573c8f48e2d7d92a4d8959 Mon Sep 17 00:00:00 2001 From: Josh Hagins Date: Mon, 4 Jan 2016 18:08:06 -0500 Subject: [PATCH 3/5] Print error messages to stderr --- lib/hbc/cli.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/hbc/cli.rb b/lib/hbc/cli.rb index e78dcfca41..51dae6506c 100644 --- a/lib/hbc/cli.rb +++ b/lib/hbc/cli.rb @@ -116,13 +116,13 @@ class Hbc::CLI run_command(command, *rest) rescue Hbc::CaskError, Hbc::CaskSha256MismatchError => e onoe e - puts Hbc::Utils.error_message_with_suggestions if e.is_a?(Hbc::CaskHeaderParseError) + $stderr.puts Hbc::Utils.error_message_with_suggestions if e.is_a?(Hbc::CaskHeaderParseError) $stderr.puts e.backtrace if Hbc.debug exit 1 rescue StandardError, ScriptError, NoMemoryError => e onoe e - puts Hbc::Utils.error_message_with_suggestions - puts e.backtrace + $stderr.puts Hbc::Utils.error_message_with_suggestions + $stderr.puts e.backtrace exit 1 end From a23e270414798e1df8bab48270dc8b0395777fca Mon Sep 17 00:00:00 2001 From: Josh Hagins Date: Mon, 4 Jan 2016 18:12:13 -0500 Subject: [PATCH 4/5] Use global var $stderr instead of constant STDERR --- developer/bin/generate_cask_token | 6 +++--- lib/hbc/system_command.rb | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/developer/bin/generate_cask_token b/developer/bin/generate_cask_token index acc2f84a8e..08eeb4310a 100755 --- a/developer/bin/generate_cask_token +++ b/developer/bin/generate_cask_token @@ -384,9 +384,9 @@ def report puts "Proposed file name: #{cask_file_name}" puts "Cask Header Line: cask '#{cask_token}' do" if warnings.length > 0 - STDERR.puts "\n" - STDERR.puts warnings - STDERR.puts "\n" + $stderr.puts "\n" + $stderr.puts warnings + $stderr.puts "\n" exit 1 end end diff --git a/lib/hbc/system_command.rb b/lib/hbc/system_command.rb index 872c46d671..c07353470e 100644 --- a/lib/hbc/system_command.rb +++ b/lib/hbc/system_command.rb @@ -93,7 +93,7 @@ class Hbc::SystemCommand::Result external = File.basename(command.first) lines = garbage.strip.split("\n") opoo "Non-XML stdout from #{external}:" - STDERR.puts lines.map {|l| " #{l}"} + $stderr.puts lines.map {|l| " #{l}"} end def self._parse_plist(command, output) From e42966644cefc821f28acf31e71a4b143a04934d Mon Sep 17 00:00:00 2001 From: Josh Hagins Date: Mon, 4 Jan 2016 23:22:19 -0500 Subject: [PATCH 5/5] Add `brew untap phinze/cask` to UPDATE_CMD --- lib/hbc/utils.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/hbc/utils.rb b/lib/hbc/utils.rb index a25fb23fe7..60194a5151 100644 --- a/lib/hbc/utils.rb +++ b/lib/hbc/utils.rb @@ -6,7 +6,7 @@ require 'stringio' require 'hbc/utils/tty' -UPDATE_CMD = "brew uninstall --force brew-cask; brew update; brew cleanup; brew cask cleanup" +UPDATE_CMD = "brew uninstall --force brew-cask; brew untap phinze/cask; brew update; brew cleanup; brew cask cleanup" ISSUES_URL = "https://github.com/caskroom/homebrew-cask#reporting-bugs" # todo: temporary