Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Colorize buildpack failures #788

Merged
merged 4 commits into from
Jul 5, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 1 addition & 10 deletions bin/support/ruby_compile
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,5 @@ begin
end
end
rescue Exception => e
Kernel.puts " !"
e.message.split("\n").each do |line|
Kernel.puts " ! #{line.strip}"
end
Kernel.puts " !"
if e.is_a?(BuildpackError)
exit 1
else
raise e
end
LanguagePack::ShellHelpers.display_error_and_exit(e)
end
12 changes: 2 additions & 10 deletions bin/support/ruby_test-compile
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ $:.unshift File.expand_path("../../../lib", __FILE__)
require "language_pack"
require "language_pack/shell_helpers"
require "language_pack/test"
include LanguagePack::ShellHelpers

begin
LanguagePack::Instrument.trace 'test_compile', 'app.test_compile' do
Expand All @@ -28,14 +29,5 @@ begin
end
end
rescue Exception => e
Kernel.puts " !"
e.message.split("\n").each do |line|
Kernel.puts " ! #{line.strip}"
end
Kernel.puts " !"
if e.is_a?(BuildpackError)
exit 1
else
raise e
end
LanguagePack::ShellHelpers.display_error_and_exit(e)
end
4 changes: 3 additions & 1 deletion lib/language_pack/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,16 @@ def compile
instrument 'base.compile' do
Kernel.puts ""
warnings.each do |warning|
Kernel.puts "###### WARNING:\n"
Kernel.puts "\e[1m\e[33m###### WARNING:\e[0m"# Bold yellow
Kernel.puts ""
puts warning
Kernel.puts ""
end
if deprecations.any?
topic "DEPRECATIONS:"
puts @deprecations.join("\n")
end
Kernel.puts ""
end
mcount "success"
end
Expand Down
20 changes: 19 additions & 1 deletion lib/language_pack/shell_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,22 @@ def self.initialize_env(path)
end
end

# Should only be used once in the top level script
# for example $ bin/support/ruby_compile
def self.display_error_and_exit(e)
Kernel.puts "\e[1m\e[31m" # Bold Red
Kernel.puts " !"
e.message.split("\n").each do |line|
Kernel.puts " ! #{line.strip}"
end
Kernel.puts " !\e[0m"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same question here

if e.is_a?(BuildpackError)
exit 1
else
raise e
end
end

# run a shell command (deferring to #run), and raise an error if it fails
# @param [String] command to be run
# @return [String] result of #run
Expand Down Expand Up @@ -243,7 +259,9 @@ def puts(message)

def warn(message, options = {})
if options.key?(:inline) ? options[:inline] : false
Kernel.puts "###### WARNING:"
Kernel.puts ""
Kernel.puts "\e[1m\e[33m###### WARNING:\e[0m" # Bold yellow
Kernel.puts ""
puts message
Kernel.puts ""
end
Expand Down