Skip to content

Commit

Permalink
Spike: store exceptions to be reported later
Browse files Browse the repository at this point in the history
  • Loading branch information
jurre committed Apr 24, 2024
1 parent fc590a7 commit ad42509
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 1 deletion.
34 changes: 34 additions & 0 deletions common/lib/dependabot/exception_capturer.rb
@@ -0,0 +1,34 @@
# typed: strong
# frozen_string_literal: true

require "sorbet-runtime"

module Dependabot
module ExceptionCapturer
extend T::Sig

# An array of captured exceptions stored for later retrieval
@captured_exceptions = T.let([], T::Array[StandardError])

sig { params(error: StandardError).void }
def self.capture_exception(error:)
@captured_exceptions << error
end

sig { params(block: T.proc.params(error: StandardError).void).void }
def self.handle_captured_exceptions(&block)
@captured_exceptions.each(&block)
clear_captured_exceptions
end

sig { returns(T::Array[StandardError]) }
def self.captured_exceptions
@captured_exceptions
end

sig { void }
def self.clear_captured_exceptions
@captured_exceptions = []
end
end
end
Expand Up @@ -887,6 +887,7 @@ def package_manager

sig { params(method: String, err: StandardError).void }
def suppress_error(method, err)
Dependabot::ExceptionCapturer.capture_exception(error: err)
Dependabot.logger.error("Error while generating #{method}: #{err.message}")
Dependabot.logger.error(err.backtrace&.join("\n"))
end
Expand Down
8 changes: 7 additions & 1 deletion updater/bin/update_files.rb
Expand Up @@ -10,6 +10,7 @@
require "dependabot/service"
require "dependabot/setup"
require "dependabot/update_files_command"
require "dependabot/exception_capturer"
require "debug" if ENV["DEBUG"]

flamegraph = ENV.fetch("FLAMEGRAPH", nil)
Expand All @@ -31,7 +32,12 @@ class UpdaterKilledError < StandardError; end
Dependabot::Environment.job_id,
Dependabot::Environment.job_token
)
Dependabot::Service.new(client: api_client).capture_exception(error: error, tags: tags)
service = Dependabot::Service.new(client: api_client)

Dependabot::ExceptionCapturer.handle_captured_exceptions do |exception|
service.capture_exception(error: exception, tags: tags)
end
service.capture_exception(error: error, tags: tags)
exit
end

Expand Down
4 changes: 4 additions & 0 deletions updater/lib/dependabot/update_files_command.rb
Expand Up @@ -51,6 +51,10 @@ def perform_job
# successfully processed unless it actually raises.
service.mark_job_as_processed(dependency_snapshot.base_commit_sha)
end
ensure
Dependabot::ExceptionCapturer.handle_captured_exceptions do |exception|
service.capture_exception(error: exception, job: job)
end
end

private
Expand Down

0 comments on commit ad42509

Please sign in to comment.