oopsie-ruby 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: 2e85dbb6b0f79d5c507a3946954eb6d8bf0535608511f0acd3d096b610378f8c
4
+ data.tar.gz: 67f2bea5aff602e5b740829545a89c4b57ff922dc8ef17e5c773cb844bbb8d9d
5
+ SHA512:
6
+ metadata.gz: 04f073013567b2a8568592f868eb2b76b8ea60bb35b28bf6edb7612d5272552d3ffa3e20a6f771505a9242212f6d760f8fb8fa950f62c9840531704ce4fb9b3d
7
+ data.tar.gz: 4d903125f43c396cf03c50a07977862058b306b7a424ae0138e074b75bd1530d07d25964e72c244cbd5e1d0317b1b98a3b60a3ea947a2f0a1049940d99fb4e51
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Oopsie
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/README.md ADDED
@@ -0,0 +1,84 @@
1
+ # oopsie-ruby
2
+
3
+ Lightweight Ruby gem that reports exceptions to an [Oopsie](https://github.com/jacobespersen/oopsie) instance.
4
+
5
+ - Zero runtime dependencies (uses Ruby stdlib)
6
+ - Rack middleware for automatic error capture
7
+ - Manual `Oopsie.report(e)` API
8
+ - Silent failures with optional `on_error` callback
9
+
10
+ ## Installation
11
+
12
+ Add to your Gemfile:
13
+
14
+ ```ruby
15
+ gem "oopsie-ruby"
16
+ ```
17
+
18
+ Then run:
19
+
20
+ ```bash
21
+ bundle install
22
+ ```
23
+
24
+ ## Configuration
25
+
26
+ ```ruby
27
+ Oopsie.configure do |config|
28
+ config.api_key = ENV["OOPSIE_API_KEY"]
29
+ config.endpoint = "https://your-oopsie-instance.com"
30
+
31
+ # Optional: called when error reporting itself fails
32
+ config.on_error = ->(e) { Rails.logger.warn("Oopsie error: #{e.message}") }
33
+ end
34
+ ```
35
+
36
+ ### Rails initializer
37
+
38
+ Create `config/initializers/oopsie.rb`:
39
+
40
+ ```ruby
41
+ Oopsie.configure do |config|
42
+ config.api_key = Rails.application.credentials.oopsie_api_key
43
+ config.endpoint = "https://your-oopsie-instance.com"
44
+ end
45
+ ```
46
+
47
+ ## Rack Middleware
48
+
49
+ Add the middleware to automatically capture unhandled exceptions:
50
+
51
+ ```ruby
52
+ # config.ru
53
+ use Oopsie::Middleware
54
+ ```
55
+
56
+ In Rails, add to `config/application.rb`:
57
+
58
+ ```ruby
59
+ config.middleware.use Oopsie::Middleware
60
+ ```
61
+
62
+ The middleware reports the error and re-raises it, so your existing error handling is unaffected.
63
+
64
+ ## Manual Reporting
65
+
66
+ Report exceptions anywhere in your code:
67
+
68
+ ```ruby
69
+ begin
70
+ do_something_risky
71
+ rescue => e
72
+ Oopsie.report(e)
73
+ end
74
+ ```
75
+
76
+ `Oopsie.report` never raises — if reporting fails, it silently swallows the error (or calls your `on_error` callback).
77
+
78
+ ## Requirements
79
+
80
+ - Ruby >= 3.1
81
+
82
+ ## License
83
+
84
+ MIT
@@ -0,0 +1,62 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'net/http'
4
+ require 'json'
5
+ require 'uri'
6
+
7
+ module Oopsie
8
+ class DeliveryError < StandardError; end
9
+
10
+ class Client
11
+ ERRORS_PATH = '/api/v1/errors'
12
+ CONNECT_TIMEOUT = 5
13
+ READ_TIMEOUT = 10
14
+
15
+ def initialize(configuration)
16
+ @configuration = configuration
17
+ end
18
+
19
+ def send_error(error_class:, message:, stack_trace:)
20
+ uri = URI.join(@configuration.endpoint, ERRORS_PATH)
21
+ request = build_request(uri, error_class:, message:, stack_trace:)
22
+ response = execute(uri, request)
23
+ handle_response(response)
24
+ rescue StandardError => e
25
+ notify_error(e)
26
+ end
27
+
28
+ private
29
+
30
+ def build_request(uri, error_class:, message:, stack_trace:)
31
+ request = Net::HTTP::Post.new(uri)
32
+ request['Content-Type'] = 'application/json'
33
+ request['Authorization'] = "Bearer #{@configuration.api_key}"
34
+ request.body = JSON.generate(
35
+ error_class: error_class,
36
+ message: message,
37
+ stack_trace: stack_trace
38
+ )
39
+ request
40
+ end
41
+
42
+ def execute(uri, request)
43
+ http = Net::HTTP.new(uri.host, uri.port)
44
+ http.use_ssl = uri.scheme == 'https'
45
+ http.open_timeout = CONNECT_TIMEOUT
46
+ http.read_timeout = READ_TIMEOUT
47
+ http.request(request)
48
+ end
49
+
50
+ def handle_response(response)
51
+ return if response.is_a?(Net::HTTPSuccess)
52
+
53
+ raise DeliveryError, "Oopsie API returned #{response.code}: #{response.body}"
54
+ end
55
+
56
+ def notify_error(error)
57
+ @configuration.on_error&.call(error)
58
+ rescue StandardError
59
+ # Never let callback errors escape
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Oopsie
4
+ class ConfigurationError < StandardError; end
5
+
6
+ class Configuration
7
+ attr_accessor :api_key, :on_error
8
+ attr_reader :endpoint
9
+
10
+ def endpoint=(value)
11
+ @endpoint = value&.chomp('/')
12
+ end
13
+
14
+ def validate!
15
+ raise ConfigurationError, 'api_key is required' if api_key.nil? || api_key.empty?
16
+ raise ConfigurationError, 'endpoint is required' if endpoint.nil? || endpoint.empty?
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Oopsie
4
+ class Middleware
5
+ def initialize(app)
6
+ @app = app
7
+ end
8
+
9
+ def call(env)
10
+ @app.call(env)
11
+ rescue Exception => e # rubocop:disable Lint/RescueException
12
+ Oopsie.report(e)
13
+ raise
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Oopsie
4
+ VERSION = '0.1.0'
5
+ end
data/lib/oopsie.rb ADDED
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'oopsie/version'
4
+ require_relative 'oopsie/configuration'
5
+ require_relative 'oopsie/client'
6
+ require_relative 'oopsie/middleware'
7
+
8
+ module Oopsie
9
+ class << self
10
+ def configuration
11
+ @configuration ||= Configuration.new
12
+ end
13
+
14
+ def configure
15
+ yield(configuration)
16
+ end
17
+
18
+ def reset_configuration!
19
+ @configuration = Configuration.new
20
+ end
21
+
22
+ def report(exception)
23
+ configuration.validate!
24
+ Client.new(configuration).send_error(
25
+ error_class: exception.class.name,
26
+ message: exception.message,
27
+ stack_trace: exception.backtrace&.join("\n")
28
+ )
29
+ rescue StandardError => e
30
+ safely_notify_error(e)
31
+ end
32
+
33
+ private
34
+
35
+ def safely_notify_error(error)
36
+ configuration.on_error&.call(error)
37
+ rescue StandardError
38
+ # Never crash the host app
39
+ end
40
+ end
41
+ end
metadata ADDED
@@ -0,0 +1,131 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: oopsie-ruby
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Oopsie
8
+ bindir: bin
9
+ cert_chain: []
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
+ dependencies:
12
+ - !ruby/object:Gem::Dependency
13
+ name: bundler
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - "~>"
17
+ - !ruby/object:Gem::Version
18
+ version: '2.0'
19
+ type: :development
20
+ prerelease: false
21
+ version_requirements: !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - "~>"
24
+ - !ruby/object:Gem::Version
25
+ version: '2.0'
26
+ - !ruby/object:Gem::Dependency
27
+ name: rack-test
28
+ requirement: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - "~>"
31
+ - !ruby/object:Gem::Version
32
+ version: '2.1'
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '2.1'
40
+ - !ruby/object:Gem::Dependency
41
+ name: rake
42
+ requirement: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: '13.0'
47
+ type: :development
48
+ prerelease: false
49
+ version_requirements: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - "~>"
52
+ - !ruby/object:Gem::Version
53
+ version: '13.0'
54
+ - !ruby/object:Gem::Dependency
55
+ name: rspec
56
+ requirement: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - "~>"
59
+ - !ruby/object:Gem::Version
60
+ version: '3.12'
61
+ type: :development
62
+ prerelease: false
63
+ version_requirements: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - "~>"
66
+ - !ruby/object:Gem::Version
67
+ version: '3.12'
68
+ - !ruby/object:Gem::Dependency
69
+ name: rubocop
70
+ requirement: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - "~>"
73
+ - !ruby/object:Gem::Version
74
+ version: '1.50'
75
+ type: :development
76
+ prerelease: false
77
+ version_requirements: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - "~>"
80
+ - !ruby/object:Gem::Version
81
+ version: '1.50'
82
+ - !ruby/object:Gem::Dependency
83
+ name: webmock
84
+ requirement: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - "~>"
87
+ - !ruby/object:Gem::Version
88
+ version: '3.18'
89
+ type: :development
90
+ prerelease: false
91
+ version_requirements: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - "~>"
94
+ - !ruby/object:Gem::Version
95
+ version: '3.18'
96
+ description: Lightweight Ruby gem that reports exceptions to an Oopsie instance. Includes
97
+ Rack middleware for automatic capture and a manual reporting API.
98
+ executables: []
99
+ extensions: []
100
+ extra_rdoc_files: []
101
+ files:
102
+ - LICENSE
103
+ - README.md
104
+ - lib/oopsie.rb
105
+ - lib/oopsie/client.rb
106
+ - lib/oopsie/configuration.rb
107
+ - lib/oopsie/middleware.rb
108
+ - lib/oopsie/version.rb
109
+ homepage: https://github.com/jacobespersen/oopsie-ruby
110
+ licenses:
111
+ - MIT
112
+ metadata:
113
+ rubygems_mfa_required: 'true'
114
+ rdoc_options: []
115
+ require_paths:
116
+ - lib
117
+ required_ruby_version: !ruby/object:Gem::Requirement
118
+ requirements:
119
+ - - ">="
120
+ - !ruby/object:Gem::Version
121
+ version: '3.1'
122
+ required_rubygems_version: !ruby/object:Gem::Requirement
123
+ requirements:
124
+ - - ">="
125
+ - !ruby/object:Gem::Version
126
+ version: '0'
127
+ requirements: []
128
+ rubygems_version: 3.6.9
129
+ specification_version: 4
130
+ summary: Ruby client for Oopsie error reporting
131
+ test_files: []