format_exception 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 +7 -0
- data/.gitignore +9 -0
- data/.rspec +2 -0
- data/Gemfile +4 -0
- data/README.md +36 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/format_exception.gemspec +24 -0
- data/lib/format_exception/version.rb +3 -0
- data/lib/format_exception.rb +81 -0
- metadata +96 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: d80328dd66e21a3a58ca8d3ba455a2fc51220e75
|
4
|
+
data.tar.gz: 2dffab1f7c1421c02a622797e2e4ddbbb4bd0008
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 64ca99310e1ebdbb3ffd5023f427e7dc4c4db8eb50d2f9cda1c6c5934c0f5405f8286955f39ded23eec1420d7e94c3e2054714e49387370418e6b9bdb07bb726
|
7
|
+
data.tar.gz: 998c51089e13986a3d5f625310aebdefe0736d377885c0b413fdb11ba6b125419167b904e4628f11c31d952e1680af451db770638dc07a1af82537118e290c48
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
# FormatException
|
2
|
+
|
3
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/format_exception`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
|
+
|
5
|
+
TODO: Delete this and the text above, and describe your gem
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'format_exception'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install format_exception
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
TODO: Write usage instructions here
|
26
|
+
|
27
|
+
## Development
|
28
|
+
|
29
|
+
After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
30
|
+
|
31
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
32
|
+
|
33
|
+
## Contributing
|
34
|
+
|
35
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/format_exception.
|
36
|
+
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "format_exception"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'format_exception/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "format_exception"
|
8
|
+
spec.version = FormatException::VERSION
|
9
|
+
spec.authors = ["Sheldon Hearn"]
|
10
|
+
spec.email = ["sheldonh@starjuice.net"]
|
11
|
+
|
12
|
+
spec.summary = %q{Exception formatter}
|
13
|
+
spec.description = %q{A tiny exception formatter}
|
14
|
+
spec.homepage = "https://github.com/hetznerZA/format_exception"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
17
|
+
spec.bindir = "exe"
|
18
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.12"
|
22
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
23
|
+
spec.add_development_dependency "rspec", "~> 3.5"
|
24
|
+
end
|
@@ -0,0 +1,81 @@
|
|
1
|
+
require "format_exception/version"
|
2
|
+
|
3
|
+
##
|
4
|
+
# Simple exception formatter
|
5
|
+
#
|
6
|
+
# Provides utility methods for formatting an exception as a String.
|
7
|
+
#
|
8
|
+
# @example The contextual clean format
|
9
|
+
#
|
10
|
+
# require "logger"
|
11
|
+
# require "format_exception"
|
12
|
+
#
|
13
|
+
# logger = Logger.new($stderr)
|
14
|
+
# begin
|
15
|
+
# File.open("message.txt", "r") do |io|
|
16
|
+
# puts io.read
|
17
|
+
# end
|
18
|
+
# rescue IOError => ex
|
19
|
+
# logger.error(FormatException[ex, "Printing welcome message"])
|
20
|
+
# end
|
21
|
+
#
|
22
|
+
# # Prints
|
23
|
+
# #
|
24
|
+
# # E, [2017-02-11T01:56:08.763049 #4302] ERROR -- : Printing welcome message: Errno::ENOENT: No such file or directory @ rb_sysopen - message.txt:
|
25
|
+
# # foo.rb:10:in `initialize'
|
26
|
+
# # foo.rb:10:in `open'
|
27
|
+
# # foo.rb:10:in `<main>'
|
28
|
+
#
|
29
|
+
module FormatException
|
30
|
+
|
31
|
+
##
|
32
|
+
# The contextual clean format
|
33
|
+
#
|
34
|
+
# Format the exception as per {clean}, but with an optional +context_message+
|
35
|
+
# prepended to the first line.
|
36
|
+
#
|
37
|
+
# @param [Exception] e
|
38
|
+
# the exception to format
|
39
|
+
# @param [String] context_message
|
40
|
+
# the additional message to prepend to the formatted exception
|
41
|
+
# @return [String] the formatted exception
|
42
|
+
#
|
43
|
+
def self.[](e, context_message = nil)
|
44
|
+
if context_message
|
45
|
+
"#{context_message}: " + clean(e)
|
46
|
+
else
|
47
|
+
clean(e)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
##
|
52
|
+
# The Ruby interpreter's default format
|
53
|
+
#
|
54
|
+
# Formats the exception exactly as the Ruby interpreter would if the exception
|
55
|
+
# was uncaught. The first line includes the first line of the backtrace, and the
|
56
|
+
# exception class name and message, with the rest of the backtrace on subsequent,
|
57
|
+
# indented lines.
|
58
|
+
#
|
59
|
+
# @param [Exception] e
|
60
|
+
# the exception to format
|
61
|
+
# @return [String] the formatted exception
|
62
|
+
#
|
63
|
+
def self.classic(e)
|
64
|
+
"#{e.backtrace.first}: #{e.message} (#{e.class})\n\t" + e.backtrace.drop(1).join("\n\t")
|
65
|
+
end
|
66
|
+
|
67
|
+
##
|
68
|
+
# The log-friendly format
|
69
|
+
#
|
70
|
+
# Formats the exception as the Rails logger would, with the exception class name
|
71
|
+
# and message on the first line, with the backtrace on subsequent, indented lines.
|
72
|
+
#
|
73
|
+
# @param [Exception] e
|
74
|
+
# the exception to format
|
75
|
+
# @return [String] the formatted exception
|
76
|
+
#
|
77
|
+
def self.clean(e)
|
78
|
+
"#{e.class}: #{e.message}:\n\t" + e.backtrace.join("\n\t")
|
79
|
+
end
|
80
|
+
|
81
|
+
end
|
metadata
ADDED
@@ -0,0 +1,96 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: format_exception
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Sheldon Hearn
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-02-11 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.12'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.12'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.5'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.5'
|
55
|
+
description: A tiny exception formatter
|
56
|
+
email:
|
57
|
+
- sheldonh@starjuice.net
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- ".gitignore"
|
63
|
+
- ".rspec"
|
64
|
+
- Gemfile
|
65
|
+
- README.md
|
66
|
+
- Rakefile
|
67
|
+
- bin/console
|
68
|
+
- bin/setup
|
69
|
+
- format_exception.gemspec
|
70
|
+
- lib/format_exception.rb
|
71
|
+
- lib/format_exception/version.rb
|
72
|
+
homepage: https://github.com/hetznerZA/format_exception
|
73
|
+
licenses: []
|
74
|
+
metadata: {}
|
75
|
+
post_install_message:
|
76
|
+
rdoc_options: []
|
77
|
+
require_paths:
|
78
|
+
- lib
|
79
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - ">="
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: '0'
|
84
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - ">="
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '0'
|
89
|
+
requirements: []
|
90
|
+
rubyforge_project:
|
91
|
+
rubygems_version: 2.5.1
|
92
|
+
signing_key:
|
93
|
+
specification_version: 4
|
94
|
+
summary: Exception formatter
|
95
|
+
test_files: []
|
96
|
+
has_rdoc:
|