catchex 0.0.8 → 0.0.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (4) hide show
  1. data/Rakefile +1 -1
  2. data/bin/rake +13 -5
  3. data/lib/catchex.rb +53 -13
  4. metadata +3 -3
data/Rakefile CHANGED
@@ -12,7 +12,7 @@ require 'rake/testtask'
12
12
  require 'fileutils'
13
13
  spec = Gem::Specification.new do |s|
14
14
  s.name = 'catchex'
15
- s.version = '0.0.8'
15
+ s.version = '0.0.9'
16
16
  s.has_rdoc = false
17
17
  s.bindir = 'bin'
18
18
  s.add_dependency('rake', '>= 0.8')
data/bin/rake CHANGED
@@ -27,15 +27,23 @@ begin
27
27
  rescue LoadError
28
28
  end
29
29
 
30
+ begin
31
+ require "catchex"
32
+ rescue LoadError
33
+ end
34
+
30
35
  require 'rake'
31
36
 
32
37
  begin
38
+ Rake.class_eval do
39
+ class << self
40
+ def application
41
+ @application ||= CatchEx::RakeExt::ApplicationExt.new
42
+ end
43
+ end
44
+ end
33
45
  Rake.application.run
34
46
  rescue Exception => e
35
- begin
36
- require "catchex"
37
- CatchEx.catch(e, Rake.application.top_level_tasks.first)
38
- rescue LoadError
39
- end
47
+ CatchEx.catch(e, Rake.application.top_level_tasks.first)if defined? CatchEx
40
48
  raise e
41
49
  end
data/lib/catchex.rb CHANGED
@@ -15,19 +15,29 @@ module CatchEx
15
15
  @@scenario = ""
16
16
  @@excepted = []
17
17
 
18
- def self.project_key(project_key = nil)
19
- unless project_key.nil?
20
- @@project_key = project_key
21
- else
22
- return @@project_key
18
+ class << self
19
+ def project_key(project_key = nil)
20
+ unless project_key.nil?
21
+ @@project_key = project_key
22
+ else
23
+ return @@project_key
24
+ end
25
+ end
26
+
27
+ def include_ex?(ex_class)
28
+ @@excepted.include? ex_class
29
+ end
30
+
31
+ def add_excepted_ex(ex_class)
32
+ @@excepted << ex_class
23
33
  end
24
- end
25
34
 
26
- def self.scenario(scenario = nil)
27
- unless scenario.nil?
28
- @@scenario = scenario
29
- else
30
- return @@scenario
35
+ def scenario(scenario = nil)
36
+ unless scenario.nil?
37
+ @@scenario = scenario
38
+ else
39
+ return @@scenario
40
+ end
31
41
  end
32
42
  end
33
43
  end
@@ -37,7 +47,7 @@ module CatchEx
37
47
  def configure
38
48
  yield Config
39
49
  if defined? ActionController::RoutingError
40
- @@scenario << ActionController::RoutingError unless @@scenario.include? ActionController::RoutingError
50
+ Config.add_excepted_ex ActionController::RoutingError unless Config.include_ex? ActionController::RoutingError
41
51
  end
42
52
  end
43
53
 
@@ -55,7 +65,7 @@ module CatchEx
55
65
 
56
66
  # The catch_ex is a convenient method for posting exception.
57
67
  def catch(exception, from = "", url = "", params = {})
58
- return if Config.project_key.blank? || Config.scenario.blank? || @@excepted.include?(exception.class)
68
+ return if Config.project_key.blank? || Config.scenario.blank? || Config.include_ex?(exception.class)
59
69
  begin
60
70
  Net::HTTP.post_form(URI.parse(@@DATA_PUSH_URL), {:version => @@PLUGIN_VERSION, :language => @@LANGUAGE,
61
71
  :project_key => Config.project_key, :local_ip => local_ip, :message => exception.message, :scenario => Config.scenario,
@@ -65,6 +75,36 @@ module CatchEx
65
75
  end
66
76
  end
67
77
 
78
+ module RakeExt
79
+
80
+ class ApplicationExt < Rake::Application
81
+ def standard_exception_handling
82
+ begin
83
+ yield
84
+ rescue SystemExit => ex
85
+ # Exit silently with current status
86
+ CatchEx.catch(ex, Rake.application.top_level_tasks.first) if defined? CatchEx
87
+ raise
88
+ rescue OptionParser::InvalidOption => ex
89
+ # Exit silently
90
+ exit(false)
91
+ rescue Exception => ex
92
+ # Exit with error message
93
+ $stderr.puts "#{name} aborted!"
94
+ $stderr.puts ex.message
95
+ if options.trace
96
+ $stderr.puts ex.backtrace.join("\n")
97
+ else
98
+ $stderr.puts ex.backtrace.find {|str| str =~ /#{@rakefile}/ } || ""
99
+ $stderr.puts "(See full trace by running task with --trace)"
100
+ end
101
+ CatchEx.catch(ex, Rake.application.top_level_tasks.first) if defined? CatchEx
102
+ exit(false)
103
+ end
104
+ end
105
+ end
106
+ end
107
+
68
108
  module ActionControllerExt
69
109
  def self.included(base) #:nodoc:
70
110
  base.send :include, InstanceMethods
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: catchex
3
3
  version: !ruby/object:Gem::Version
4
- hash: 15
4
+ hash: 13
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 8
10
- version: 0.0.8
9
+ - 9
10
+ version: 0.0.9
11
11
  platform: ruby
12
12
  authors:
13
13
  - Braisdom