Sha256: 979fedbce3439da986e7a95a1a6661bb0c9b6424d6614347734652de5d6d98e9

Contents?: true

Size: 1.02 KB

Versions: 14

Compression:

Stored size: 1.02 KB

Contents

# frozen_string_literal: true

require "active_job/serializers/object_serializer"

module AcidicJob
  module Serializers
    class ExceptionSerializer < ::ActiveJob::Serializers::ObjectSerializer
      def serialize(exception)
        hash = {
          "class" => exception.class.name,
          "message" => exception.message,
          "cause" => exception.cause,
          "backtrace" => {}
        }

        exception.backtrace.map do |trace|
          path, _, location = trace.rpartition("/")

          next if hash["backtrace"].key?(path)

          hash["backtrace"][path] = location
        end

        super(hash)
      end

      def deserialize(hash)
        exception_class = hash["class"].constantize
        exception = exception_class.new(hash["message"])
        exception.set_backtrace(hash["backtrace"].map do |path, location|
          [path, location].join("/")
        end)
        exception
      end

      def serialize?(argument)
        defined?(Exception) && argument.is_a?(Exception)
      end
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
acidic_job-0.8.3 lib/acidic_job/serializers/exception_serializer.rb
acidic_job-0.8.2 lib/acidic_job/serializers/exception_serializer.rb
acidic_job-0.8.1 lib/acidic_job/serializers/exception_serializer.rb
acidic_job-0.8.0 lib/acidic_job/serializers/exception_serializer.rb
acidic_job-1.0.0.beta.10 lib/acidic_job/serializers/exception_serializer.rb
acidic_job-1.0.0.beta.9 lib/acidic_job/serializers/exception_serializer.rb
acidic_job-1.0.0.beta.8 lib/acidic_job/serializers/exception_serializer.rb
acidic_job-1.0.0.beta.7 lib/acidic_job/serializers/exception_serializer.rb
acidic_job-1.0.0.beta.6 lib/acidic_job/serializers/exception_serializer.rb
acidic_job-1.0.0.beta.5 lib/acidic_job/serializers/exception_serializer.rb
acidic_job-1.0.0.beta.4 lib/acidic_job/serializers/exception_serializer.rb
acidic_job-1.0.0.beta.3 lib/acidic_job/serializers/exception_serializer.rb
acidic_job-1.0.0.beta.2 lib/acidic_job/serializers/exception_serializer.rb
acidic_job-1.0.0.beta.1 lib/acidic_job/serializers/exception_serializer.rb