error_extractor 0.1.0

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 5d54c336193340a9be9623b913bbc983c11f5d51ada0396faa6afe0e74631b62
4
+ data.tar.gz: bc6fbda96ef8a92b3f942fab6e3bcea0ebc0b4cba356e65de2be1619ebde84da
5
+ SHA512:
6
+ metadata.gz: 4ef1ae651f583db8517f1aeac0ca7a21d4e002f41698f7515aceba6fd4cca8e837b5d6d4908a3d4db4af5fc7f555d73f38022cc11d2c065615e3966ae81d8afd
7
+ data.tar.gz: 1cd438f7090ba162bd965d9f9d6d019212c87fe66d98d87732294d03d59d1b4deeaddf70bf60bb8f5f4798893ff6579c375365328dddfe1960a6bf6831651870
data/.ruby-gemset ADDED
@@ -0,0 +1 @@
1
+ error_extractor
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 3.2.2
data/Gemfile ADDED
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in error_extractor.gemspec
6
+ gemspec
7
+
8
+ gem "rake", "~> 13.0"
9
+
10
+ gem "minitest", "~> 5.0"
11
+ gem "awesome_print"
data/Gemfile.lock ADDED
@@ -0,0 +1,23 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ error_extractor (0.1.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ awesome_print (1.9.2)
10
+ minitest (5.19.0)
11
+ rake (13.0.6)
12
+
13
+ PLATFORMS
14
+ x86_64-darwin-20
15
+
16
+ DEPENDENCIES
17
+ awesome_print
18
+ error_extractor!
19
+ minitest (~> 5.0)
20
+ rake (~> 13.0)
21
+
22
+ BUNDLED WITH
23
+ 2.4.10
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023 Daniel P. Zepeda
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2023 Daniel P Zepeda
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,65 @@
1
+ # ErrorExtractor
2
+
3
+ ErrorExtractor is a simple utility to extract errors from exceptions objects. It handles the different common ways an
4
+ exception message may be presented, so that you don't have to worry about how an exception object presents the information,
5
+ you just hand it to ErrorExtractor and get back a string you can print to a log or the console, etc.
6
+
7
+ ## Installation
8
+
9
+ ### Bundler
10
+
11
+ Add to your Gemfile:
12
+
13
+ gem "error_extractor" github: "duskhacker/error-extractor.git"
14
+
15
+ Then run bundler:
16
+
17
+ $ bundle
18
+
19
+ ### No Bundler
20
+
21
+ At some point I'll get this gem uploaded to rubygems.org, but in the mean time, you'll have to:
22
+
23
+ 1. Clone the Git repository.
24
+
25
+ `$ git clone git://github.com/duskhacker/error-extractor.git`
26
+
27
+ 2. Change to the new directory.
28
+
29
+ `$ cd error-extractor`
30
+
31
+ 3. Build the gem
32
+
33
+ `$ rake build`
34
+
35
+ 4. Install the gem.
36
+
37
+ `$ gem install pkg/error_extractor-[version].gem`
38
+
39
+ ## Usage
40
+
41
+ ErrorExtractor is meant to be used in rescue blocks:
42
+
43
+ ```
44
+ begin
45
+
46
+ raise "an Error!"
47
+
48
+ rescue => e
49
+ log "An error occurred during processing: #{extract_errors(e)}"
50
+ log "An error with a backtrace: #{extract_errors_with_backtrace(e)}"
51
+ end
52
+ ```
53
+
54
+ ## Development
55
+
56
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests.
57
+ You can also run `bin/console` for an interactive prompt that will allow you to experiment.
58
+
59
+ ## Contributing
60
+
61
+ Bug reports and pull requests are welcome on GitHub at https://github.com/duskhacker/error-extractor.
62
+
63
+ ## License
64
+
65
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rake/testtask"
5
+
6
+ Rake::TestTask.new(:test) do |t|
7
+ t.libs << "test"
8
+ t.libs << "lib"
9
+ t.test_files = FileList["test/**/*_test.rb"]
10
+ end
11
+
12
+ task default: :test
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/error_extractor/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "error_extractor"
7
+ spec.version = ErrorExtractor::VERSION
8
+ spec.authors = ["Daniel P Zepeda"]
9
+ spec.email = ["daniel@zepeda.ws"]
10
+
11
+ spec.summary = "Extract errors from multiple sources"
12
+ spec.description = "Extract errors from multiple sources"
13
+ spec.homepage = "https://github.com/duskhacker/error-extractor"
14
+ spec.license = "MIT"
15
+ spec.required_ruby_version = ">= 2.6.0"
16
+
17
+ # spec.metadata["allowed_push_host"] = "TODO: Set to your gem server 'https://example.com'"
18
+
19
+ spec.metadata["homepage_uri"] = spec.homepage
20
+ spec.metadata["source_code_uri"] = spec.homepage
21
+
22
+ # Specify which files should be added to the gem when it is released.
23
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
24
+ spec.files = Dir.chdir(__dir__) do
25
+ `git ls-files -z`.split("\x0").reject do |f|
26
+ (File.expand_path(f) == __FILE__) || f.start_with?(*%w[bin/ test/ spec/ features/ .git .circleci appveyor])
27
+ end
28
+ end
29
+ spec.require_paths = ["lib"]
30
+
31
+ # Uncomment to register a new dependency of your gem
32
+ # spec.add_dependency "example-gem", "~> 1.0"
33
+ end
@@ -0,0 +1,3 @@
1
+ module ErrorExtractor
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,43 @@
1
+ require_relative "error_extractor/version"
2
+
3
+ module ErrorExtractor
4
+
5
+ def self.included(base)
6
+ base.extend ClassMethods
7
+ end
8
+
9
+ def extract_errors(e)
10
+ self.class.extract_errors(e)
11
+ end
12
+
13
+ def extract_errors_with_backtrace(e)
14
+ self.class.extract_errors_with_backtrace(e)
15
+ end
16
+
17
+ module ClassMethods
18
+ def extract_errors(e)
19
+ if e.respond_to?(:record) && __present?(e.record) && __present?(e.record&.errors&.full_messages&.to_sentence)
20
+ e.record.errors.full_messages.to_sentence
21
+ elsif e.respond_to?(:message)
22
+ e.message
23
+ elsif e.respond_to?(:to_s)
24
+ e.to_s
25
+ else
26
+ e
27
+ end
28
+ end
29
+
30
+ def extract_errors_with_backtrace(e)
31
+ "#{extract_errors(e)}\n" +
32
+ "#{e.respond_to?(:backtrace) ? e.backtrace.join("\n") : ""}"
33
+ end
34
+ end
35
+
36
+ private
37
+
38
+ def __present?(o)
39
+ !o.nil? && o != ""
40
+ end
41
+ end
42
+
43
+ include ErrorExtractor
metadata ADDED
@@ -0,0 +1,56 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: error_extractor
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Daniel P Zepeda
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2023-08-22 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Extract errors from multiple sources
14
+ email:
15
+ - daniel@zepeda.ws
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - ".ruby-gemset"
21
+ - ".ruby-version"
22
+ - Gemfile
23
+ - Gemfile.lock
24
+ - LICENSE
25
+ - LICENSE.txt
26
+ - README.md
27
+ - Rakefile
28
+ - error_extractor.gemspec
29
+ - lib/error_extractor.rb
30
+ - lib/error_extractor/version.rb
31
+ homepage: https://github.com/duskhacker/error-extractor
32
+ licenses:
33
+ - MIT
34
+ metadata:
35
+ homepage_uri: https://github.com/duskhacker/error-extractor
36
+ source_code_uri: https://github.com/duskhacker/error-extractor
37
+ post_install_message:
38
+ rdoc_options: []
39
+ require_paths:
40
+ - lib
41
+ required_ruby_version: !ruby/object:Gem::Requirement
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ version: 2.6.0
46
+ required_rubygems_version: !ruby/object:Gem::Requirement
47
+ requirements:
48
+ - - ">="
49
+ - !ruby/object:Gem::Version
50
+ version: '0'
51
+ requirements: []
52
+ rubygems_version: 3.0.3.1
53
+ signing_key:
54
+ specification_version: 4
55
+ summary: Extract errors from multiple sources
56
+ test_files: []