Skip to content
This repository

Add --cron option #43

Closed
wants to merge 5 commits into from

4 participants

Dan Lucraft Jim Weirich James M. Lawrence Rich Meyers
Dan Lucraft

This option is like --silent except if there is an error it will print a full backtrace.

The motivation for this option is cronjobs. We get emails about cron tasks if there is any output at all, hence we use --silent to quiet rake down. But if a cronjob has failed (often overnight) you would like the email to contain as much information as possible about the error, so this prints backtraces.

BTW this relies on the previous pull request about tests to make it's tests work.

Jim Weirich
Owner

Interesting idea ... I'm considering it. Not wild about the option name, I would rather name it for what it does rather than where it is intended to be used.

Dan Lucraft

Good thinking. I'm finding it hard to come up with better names that aren't verbose. --silent-trace perhaps?

James M. Lawrence
quix commented

I never understood why backtraces were suppressed in the first place. I have performed this ritual many times: swear, add --trace, re-run, wait all over again. In fact I think this was the genesis of Drake.

Rich Meyers

Besides cron jobs this will also be useful in rake tasks run during deployment. For example, when doing a fresh deployment, if a rake task fails the remote source tree is destroyed and thus even invoking rake with --trace is not easily possible.

As others said I do not understand why printing backtraces is not default behavior: #31

Jim Weirich
Owner

Rake in master now prints a truncated backtrace by default. Is this sufficient for you?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
1  .gitignore
@@ -12,3 +12,4 @@ r19.diff
12 12 temp_*
13 13 testdata
14 14 x
  15 +.redcar
11 lib/rake/application.rb
@@ -144,13 +144,13 @@ def standard_exception_handling
144 144 def display_error_message(ex)
145 145 $stderr.puts "#{name} aborted!"
146 146 $stderr.puts ex.message
147   - if options.trace
  147 + if options.trace or options.cron
148 148 $stderr.puts ex.backtrace.join("\n")
149 149 else
150 150 $stderr.puts rakefile_location(ex.backtrace)
151 151 end
152 152 $stderr.puts "Tasks: #{ex.chain}" if has_chain?(ex)
153   - $stderr.puts "(See full trace by running task with --trace)" unless options.trace
  153 + $stderr.puts "(See full trace by running task with --trace)" unless options.trace or options.cron
154 154 end
155 155
156 156 # Warn about deprecated usage.
@@ -388,6 +388,13 @@ def standard_rake_options
388 388 Rake.verbose(true)
389 389 }
390 390 ],
  391 + ['--cron', '-c', "Like -s and -X, but full backtraces are printed on errors (useful for cronjobs)",
  392 + lambda { |value|
  393 + options.cron = true
  394 + options.silent = true
  395 + options.ignore_deprecate = true
  396 + }
  397 + ],
391 398 ['--verbose', '-v', "Log message to standard output.",
392 399 lambda { |value| Rake.verbose(true) }
393 400 ],
2  test/helper.rb
@@ -35,7 +35,7 @@ def ignore_deprecations
35 35 ensure
36 36 Rake.application.options.ignore_deprecate = false
37 37 end
38   -
  38 +
39 39 end
40 40
41 41 # workarounds for 1.8
26 test/test_rake_application.rb
@@ -319,10 +319,10 @@ def test_bad_run
319 319 @app.intern(Rake::Task, "default").enhance { fail }
320 320 ARGV.clear
321 321 ARGV << '-f' << '-s' << '--rakelib=""'
322   - assert_raises(SystemExit) {
323   - _, err = capture_io { @app.run }
324   - assert_match(/see full trace/, err)
  322 + _, err = capture_io {
  323 + assert_raises(SystemExit) { @app.run }
325 324 }
  325 + assert_match(/See full trace/, err)
326 326 ensure
327 327 ARGV.clear
328 328 end
@@ -331,10 +331,24 @@ def test_bad_run_with_trace
331 331 @app.intern(Rake::Task, "default").enhance { fail }
332 332 ARGV.clear
333 333 ARGV << '-f' << '-s' << '-t'
334   - assert_raises(SystemExit) {
335   - _, err = capture_io { @app.run }
336   - refute_match(/see full trace/, err)
  334 + _, err = capture_io {
  335 + assert_raises(SystemExit) { @app.run }
  336 + }
  337 + refute_match(/See full trace/, err)
  338 + assert_match(/application.rb/, err)
  339 + ensure
  340 + ARGV.clear
  341 + end
  342 +
  343 + def test_bad_run_with_cron
  344 + @app.intern(Rake::Task, "default").enhance { fail }
  345 + ARGV.clear
  346 + ARGV << '-f' << '-s' << '-c'
  347 + _, err = capture_io {
  348 + assert_raises(SystemExit) { @app.run }
337 349 }
  350 + refute_match(/See full trace/, err)
  351 + assert_match(/application.rb/, err)
338 352 ensure
339 353 ARGV.clear
340 354 end
10 test/test_rake_application_options.rb
@@ -234,6 +234,16 @@ def test_trace
234 234 end
235 235 end
236 236
  237 + def test_cron
  238 + in_environment do
  239 + flags('--cron', '-c') do |opts|
  240 + assert opts.cron
  241 + assert opts.silent
  242 + assert opts.ignore_deprecate
  243 + end
  244 + end
  245 + end
  246 +
237 247 def test_trace_rules
238 248 in_environment do
239 249 flags('--rules') do |opts|

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.