cog-rb 0.3.7 → 0.4.1
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +16 -0
- data/lib/cog.rb +20 -1
- data/lib/cog/bundle.rb +5 -3
- data/lib/cog/command.rb +4 -0
- data/lib/cog/exception_handler.rb +34 -0
- data/lib/cog/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5744ebdbff62117795615423fdf91979144923e0
|
4
|
+
data.tar.gz: 08b1acf07b9b2ac2c11caf3058564f0958a28366
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ee86e1b20780e65b553bdd6c5d4dd5169253778ab43895936ab18eca19f6b1a3cf6852cc6d451d91b62b1fb2a4018166a51e6d0c96c447ccf804eb6630628391
|
7
|
+
data.tar.gz: 1bed07fff46d61ba59291ec66f03626c7a3d496c8d6a144d4da2bab23e8c41b313fc9e1dbd9fdc85c136b035588cbd5212979225f435895f84e1a54593dd1a27
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,19 @@
|
|
1
|
+
|
2
|
+
## 0.4.1
|
3
|
+
|
4
|
+
* Add exception handling support. You can now define a regular expression and a
|
5
|
+
block to be called when an exception whose class matches the pattern is
|
6
|
+
received. This should generally be defined in your `cog-command`. The block
|
7
|
+
will be called with the exception and `Cog::Command` instance that was
|
8
|
+
executing. Exceptions that are not matched by a pattern will be handled
|
9
|
+
normally. Here's an example:
|
10
|
+
|
11
|
+
```
|
12
|
+
Cog.error_handler.add(/Aws::.*/) do |exception, command|
|
13
|
+
Cog.return_error("#{command.name} error: #{exception.message}")
|
14
|
+
end
|
15
|
+
```
|
16
|
+
|
1
17
|
## 0.3.5
|
2
18
|
|
3
19
|
* Bugfix for "warning: toplevel constant RSpec referenced by Cog::RSpec"
|
data/lib/cog.rb
CHANGED
@@ -2,6 +2,7 @@
|
|
2
2
|
require_relative 'cog/bundle'
|
3
3
|
require_relative 'cog/config'
|
4
4
|
require_relative 'cog/command'
|
5
|
+
require_relative 'cog/exception_handler'
|
5
6
|
require_relative 'cog/request'
|
6
7
|
require_relative 'cog/response'
|
7
8
|
require_relative 'cog/version'
|
@@ -14,6 +15,24 @@ class Cog
|
|
14
15
|
def self.bundle(name)
|
15
16
|
bundle = Cog::Bundle.new(name)
|
16
17
|
yield bundle if block_given?
|
17
|
-
|
18
|
+
|
19
|
+
begin
|
20
|
+
bundle.run_command
|
21
|
+
rescue Exception => ex
|
22
|
+
error_handler.handle_exception(
|
23
|
+
exception: ex,
|
24
|
+
command: bundle.command
|
25
|
+
)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.error_handler
|
30
|
+
@@handler ||= Cog::ExceptionHandler.new
|
31
|
+
end
|
32
|
+
|
33
|
+
def self.return_error(message)
|
34
|
+
puts "COGCMD_ACTION: abort"
|
35
|
+
puts message
|
36
|
+
exit(0)
|
18
37
|
end
|
19
38
|
end
|
data/lib/cog/bundle.rb
CHANGED
@@ -20,6 +20,10 @@ class Cog
|
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
23
|
+
def command
|
24
|
+
@command ||= command_instance(ENV['COG_COMMAND'])
|
25
|
+
end
|
26
|
+
|
23
27
|
def command_instance(command_name)
|
24
28
|
command_path = command_name.split('-')
|
25
29
|
require File.join(@base_dir, 'lib', 'cog_cmd', @name, *command_path)
|
@@ -35,9 +39,7 @@ class Cog
|
|
35
39
|
end
|
36
40
|
|
37
41
|
def run_command
|
38
|
-
command
|
39
|
-
target = command_instance(command)
|
40
|
-
target.execute
|
42
|
+
command.execute
|
41
43
|
rescue Cog::Abort => exception
|
42
44
|
# Abort will end command execution and abort the pipeline
|
43
45
|
response = Cog::Response.new
|
data/lib/cog/command.rb
CHANGED
@@ -0,0 +1,34 @@
|
|
1
|
+
class Cog::ExceptionHandler
|
2
|
+
attr_accessor :handlers
|
3
|
+
|
4
|
+
def initialize
|
5
|
+
@handlers = {}
|
6
|
+
end
|
7
|
+
|
8
|
+
def add(pattern, &block)
|
9
|
+
@handlers[pattern] = block
|
10
|
+
end
|
11
|
+
|
12
|
+
def handle_exception(exception:, command:)
|
13
|
+
handlers.keys.each do |pattern|
|
14
|
+
if pattern.match(exception.class.to_s)
|
15
|
+
log_exception(exception, command)
|
16
|
+
handlers[pattern].call(exception, command)
|
17
|
+
return
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
raise exception
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def log_exception(exception, command)
|
27
|
+
log_message = {
|
28
|
+
command_name: command.name,
|
29
|
+
message: exception.message,
|
30
|
+
stack_trace: exception.backtrace
|
31
|
+
}
|
32
|
+
puts "COGCMD_ERROR: #{log_message.to_json}"
|
33
|
+
end
|
34
|
+
end
|
data/lib/cog/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cog-rb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mark Imbriaco
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-11-
|
11
|
+
date: 2016-11-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -62,6 +62,7 @@ files:
|
|
62
62
|
- lib/cog/bundle.rb
|
63
63
|
- lib/cog/command.rb
|
64
64
|
- lib/cog/config.rb
|
65
|
+
- lib/cog/exception_handler.rb
|
65
66
|
- lib/cog/exceptions.rb
|
66
67
|
- lib/cog/request.rb
|
67
68
|
- lib/cog/response.rb
|