Commit ba95021a by Tony Ta Committed by Cuong Tran

Redirect error messages to current standard error stream (#528)

parent 7c7fef30
...@@ -28,7 +28,7 @@ require 'mg' ...@@ -28,7 +28,7 @@ require 'mg'
begin begin
MG.new('annotate.gemspec') MG.new('annotate.gemspec')
rescue Exception rescue Exception
STDERR.puts("WARNING: Couldn't read gemspec. As such, a number of tasks may be unavailable to you until you run 'rake gem:gemspec' to correct the issue.") $stderr.puts("WARNING: Couldn't read gemspec. As such, a number of tasks may be unavailable to you until you run 'rake gem:gemspec' to correct the issue.")
# Gemspec is probably in a broken state, so let's give ourselves a chance to # Gemspec is probably in a broken state, so let's give ourselves a chance to
# build a new one... # build a new one...
end end
......
...@@ -169,7 +169,7 @@ module Annotate ...@@ -169,7 +169,7 @@ module Annotate
require 'rake/dsl_definition' require 'rake/dsl_definition'
rescue StandardError => e rescue StandardError => e
# We might just be on an old version of Rake... # We might just be on an old version of Rake...
puts e.message $stderr.puts e.message
exit e.status_code exit e.status_code
end end
require 'rake' require 'rake'
......
...@@ -640,8 +640,8 @@ module AnnotateModels ...@@ -640,8 +640,8 @@ module AnnotateModels
end end
end end
rescue StandardError => e rescue StandardError => e
puts "Unable to annotate #{file}: #{e.message}" $stderr.puts "Unable to annotate #{file}: #{e.message}"
puts "\t" + e.backtrace.join("\n\t") if options[:trace] $stderr.puts "\t" + e.backtrace.join("\n\t") if options[:trace]
end end
annotated annotated
...@@ -676,9 +676,9 @@ module AnnotateModels ...@@ -676,9 +676,9 @@ module AnnotateModels
model_files model_files
rescue SystemCallError rescue SystemCallError
puts "No models found in directory '#{model_dir.join("', '")}'." $stderr.puts "No models found in directory '#{model_dir.join("', '")}'."
puts "Either specify models on the command line, or use the --model-dir option." $stderr.puts "Either specify models on the command line, or use the --model-dir option."
puts "Call 'annotate --help' for more info." $stderr.puts "Call 'annotate --help' for more info."
exit 1 exit 1
end end
...@@ -786,12 +786,12 @@ module AnnotateModels ...@@ -786,12 +786,12 @@ module AnnotateModels
annotated.concat(annotate(klass, file, header, options)) if do_annotate annotated.concat(annotate(klass, file, header, options)) if do_annotate
rescue BadModelFileError => e rescue BadModelFileError => e
unless options[:ignore_unknown_models] unless options[:ignore_unknown_models]
puts "Unable to annotate #{file}: #{e.message}" $stderr.puts "Unable to annotate #{file}: #{e.message}"
puts "\t" + e.backtrace.join("\n\t") if options[:trace] $stderr.puts "\t" + e.backtrace.join("\n\t") if options[:trace]
end end
rescue StandardError => e rescue StandardError => e
puts "Unable to annotate #{file}: #{e.message}" $stderr.puts "Unable to annotate #{file}: #{e.message}"
puts "\t" + e.backtrace.join("\n\t") if options[:trace] $stderr.puts "\t" + e.backtrace.join("\n\t") if options[:trace]
end end
end end
...@@ -821,8 +821,8 @@ module AnnotateModels ...@@ -821,8 +821,8 @@ module AnnotateModels
end end
deannotated << klass if deannotated_klass deannotated << klass if deannotated_klass
rescue StandardError => e rescue StandardError => e
puts "Unable to deannotate #{File.join(file)}: #{e.message}" $stderr.puts "Unable to deannotate #{File.join(file)}: #{e.message}"
puts "\t" + e.backtrace.join("\n\t") if options[:trace] $stderr.puts "\t" + e.backtrace.join("\n\t") if options[:trace]
end end
end end
puts "Removed annotations from: #{deannotated.join(', ')}" puts "Removed annotations from: #{deannotated.join(', ')}"
......
...@@ -1676,22 +1676,22 @@ end ...@@ -1676,22 +1676,22 @@ end
EOS EOS
end end
it 'displays an error message' do it 'displays just the error message with trace disabled (default)' do
expect(capturing(:stdout) do error_output = capturing(:stderr) do
AnnotateModels.do_annotations model_dir: @model_dir, is_rake: true AnnotateModels.do_annotations model_dir: @model_dir, is_rake: true
end).to include("Unable to annotate #{@model_dir}/user.rb: oops") end
end
it 'displays the full stack trace with --trace' do expect(error_output).to include("Unable to annotate #{@model_dir}/user.rb: oops")
expect(capturing(:stdout) do expect(error_output).not_to include('/spec/annotate/annotate_models_spec.rb:')
AnnotateModels.do_annotations model_dir: @model_dir, trace: true, is_rake: true
end).to include('/spec/annotate/annotate_models_spec.rb:')
end end
it 'omits the full stack trace without --trace' do it 'displays the error message and stacktrace with trace enabled' do
expect(capturing(:stdout) do error_output = capturing(:stderr) do
AnnotateModels.do_annotations model_dir: @model_dir, trace: false, is_rake: true AnnotateModels.do_annotations model_dir: @model_dir, is_rake: true, trace: true
end).not_to include('/spec/annotate/annotate_models_spec.rb:') end
expect(error_output).to include("Unable to annotate #{@model_dir}/user.rb: oops")
expect(error_output).to include('/spec/annotate/annotate_models_spec.rb:')
end end
end end
...@@ -1706,22 +1706,22 @@ end ...@@ -1706,22 +1706,22 @@ end
EOS EOS
end end
it 'displays an error message' do it 'displays just the error message with trace disabled (default)' do
expect(capturing(:stdout) do error_output = capturing(:stderr) do
AnnotateModels.remove_annotations model_dir: @model_dir, is_rake: true AnnotateModels.remove_annotations model_dir: @model_dir, is_rake: true
end).to include("Unable to deannotate #{@model_dir}/user.rb: oops") end
end
it 'displays the full stack trace' do expect(error_output).to include("Unable to deannotate #{@model_dir}/user.rb: oops")
expect(capturing(:stdout) do expect(error_output).not_to include("/user.rb:2:in `<class:User>'")
AnnotateModels.remove_annotations model_dir: @model_dir, trace: true, is_rake: true
end).to include("/user.rb:2:in `<class:User>'")
end end
it 'omits the full stack trace without --trace' do it 'displays the error message and stacktrace with trace enabled' do
expect(capturing(:stdout) do error_output = capturing(:stderr) do
AnnotateModels.remove_annotations model_dir: @model_dir, trace: false, is_rake: true AnnotateModels.remove_annotations model_dir: @model_dir, is_rake: true, trace: true
end).not_to include("/user.rb:2:in `<class:User>'") end
expect(error_output).to include("Unable to deannotate #{@model_dir}/user.rb: oops")
expect(error_output).to include("/user.rb:2:in `<class:User>'")
end end
end end
end end
......
...@@ -63,7 +63,7 @@ module Rails ...@@ -63,7 +63,7 @@ module Rails
end end
rescue Gem::LoadError => load_error rescue Gem::LoadError => load_error
if load_error.message =~ /Could not find RubyGem rails/ if load_error.message =~ /Could not find RubyGem rails/
STDERR.puts %(Missing the Rails #{version} gem. Please `gem install -v=#{version} rails`, update your RAILS_GEM_VERSION setting in config/environment.rb for the Rails version you do have installed, or comment out RAILS_GEM_VERSION to use the latest version installed.) $stderr.puts "Missing the Rails #{version} gem. Please `gem install -v=#{version} rails`, update your RAILS_GEM_VERSION setting in config/environment.rb for the Rails version you do have installed, or comment out RAILS_GEM_VERSION to use the latest version installed."
exit 1 exit 1
else else
raise raise
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment