Browse Source

Autofix Rails/EagerEvaluationLogMessage (#23429)

* Autofix Rails/EagerEvaluationLogMessage

* Update spec for debug block syntax
closed-social-glitch-2
Nick Schonning 1 year ago
committed by GitHub
parent
commit
ed570050c6
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
17 changed files with 21 additions and 19 deletions
  1. +1
    -1
      app/lib/activitypub/activity/create.rb
  2. +1
    -1
      app/lib/link_details_extractor.rb
  3. +2
    -2
      app/models/concerns/remotable.rb
  4. +1
    -1
      app/services/activitypub/fetch_featured_collection_service.rb
  5. +1
    -1
      app/services/activitypub/fetch_remote_account_service.rb
  6. +1
    -1
      app/services/activitypub/fetch_remote_actor_service.rb
  7. +1
    -1
      app/services/activitypub/fetch_remote_key_service.rb
  8. +2
    -2
      app/services/activitypub/process_collection_service.rb
  9. +1
    -1
      app/services/activitypub/process_status_update_service.rb
  10. +1
    -1
      app/services/fetch_link_card_service.rb
  11. +1
    -1
      app/services/fetch_resource_service.rb
  12. +1
    -1
      app/services/keys/claim_service.rb
  13. +1
    -1
      app/services/keys/query_service.rb
  14. +1
    -1
      app/services/resolve_account_service.rb
  15. +1
    -1
      app/services/verify_link_service.rb
  16. +1
    -1
      app/workers/activitypub/processing_worker.rb
  17. +3
    -1
      spec/models/concerns/remotable_spec.rb

+ 1
- 1
app/lib/activitypub/activity/create.rb View File

@ -285,7 +285,7 @@ class ActivityPub::Activity::Create < ActivityPub::Activity
media_attachments
rescue Addressable::URI::InvalidURIError => e
Rails.logger.debug "Invalid URL in attachment: #{e}"
Rails.logger.debug { "Invalid URL in attachment: #{e}" }
media_attachments
end

+ 1
- 1
app/lib/link_details_extractor.rb View File

@ -248,7 +248,7 @@ class LinkDetailsExtractor
structured_data
rescue Oj::ParseError, EncodingError
Rails.logger.debug("Invalid JSON-LD in #{@original_url}")
Rails.logger.debug { "Invalid JSON-LD in #{@original_url}" }
next
end.first
end

+ 2
- 2
app/models/concerns/remotable.rb View File

@ -27,11 +27,11 @@ module Remotable
public_send("#{attachment_name}=", ResponseWithLimit.new(response, limit))
end
rescue Mastodon::UnexpectedResponseError, HTTP::TimeoutError, HTTP::ConnectionError, OpenSSL::SSL::SSLError => e
Rails.logger.debug "Error fetching remote #{attachment_name}: #{e}"
Rails.logger.debug { "Error fetching remote #{attachment_name}: #{e}" }
public_send("#{attachment_name}=", nil) if public_send("#{attachment_name}_file_name").present?
raise e unless suppress_errors
rescue Paperclip::Errors::NotIdentifiedByImageMagickError, Addressable::URI::InvalidURIError, Mastodon::HostValidationError, Mastodon::LengthValidationError, Paperclip::Error, Mastodon::DimensionsValidationError, Mastodon::StreamValidationError => e
Rails.logger.debug "Error fetching remote #{attachment_name}: #{e}"
Rails.logger.debug { "Error fetching remote #{attachment_name}: #{e}" }
public_send("#{attachment_name}=", nil) if public_send("#{attachment_name}_file_name").present?
end

+ 1
- 1
app/services/activitypub/fetch_featured_collection_service.rb View File

@ -53,7 +53,7 @@ class ActivityPub::FetchFeaturedCollectionService < BaseService
status.id
rescue ActiveRecord::RecordInvalid => e
Rails.logger.debug "Invalid pinned status #{uri}: #{e.message}"
Rails.logger.debug { "Invalid pinned status #{uri}: #{e.message}" }
nil
end

+ 1
- 1
app/services/activitypub/fetch_remote_account_service.rb View File

@ -6,7 +6,7 @@ class ActivityPub::FetchRemoteAccountService < ActivityPub::FetchRemoteActorServ
actor = super
return actor if actor.nil? || actor.is_a?(Account)
Rails.logger.debug "Fetching account #{uri} failed: Expected Account, got #{actor.class.name}"
Rails.logger.debug { "Fetching account #{uri} failed: Expected Account, got #{actor.class.name}" }
raise Error, "Expected Account, got #{actor.class.name}" unless suppress_errors
end
end

+ 1
- 1
app/services/activitypub/fetch_remote_actor_service.rb View File

@ -38,7 +38,7 @@ class ActivityPub::FetchRemoteActorService < BaseService
ActivityPub::ProcessAccountService.new.call(@username, @domain, @json, only_key: only_key, verified_webfinger: !only_key, request_id: request_id)
rescue Error => e
Rails.logger.debug "Fetching actor #{uri} failed: #{e.message}"
Rails.logger.debug { "Fetching actor #{uri} failed: #{e.message}" }
raise unless suppress_errors
end

+ 1
- 1
app/services/activitypub/fetch_remote_key_service.rb View File

@ -38,7 +38,7 @@ class ActivityPub::FetchRemoteKeyService < BaseService
find_actor(owner_uri, @owner, suppress_errors)
rescue Error => e
Rails.logger.debug "Fetching key #{uri} failed: #{e.message}"
Rails.logger.debug { "Fetching key #{uri} failed: #{e.message}" }
raise unless suppress_errors
end

+ 2
- 2
app/services/activitypub/process_collection_service.rb View File

@ -11,7 +11,7 @@ class ActivityPub::ProcessCollectionService < BaseService
begin
@json = compact(@json) if @json['signature'].is_a?(Hash)
rescue JSON::LD::JsonLdError => e
Rails.logger.debug "Error when compacting JSON-LD document for #{value_or_id(@json['actor'])}: #{e.message}"
Rails.logger.debug { "Error when compacting JSON-LD document for #{value_or_id(@json['actor'])}: #{e.message}" }
@json = original_json.without('signature')
end
@ -72,7 +72,7 @@ class ActivityPub::ProcessCollectionService < BaseService
@account = nil unless @account.is_a?(Account)
@account
rescue JSON::LD::JsonLdError, RDF::WriterError => e
Rails.logger.debug "Could not verify LD-Signature for #{value_or_id(@json['actor'])}: #{e.message}"
Rails.logger.debug { "Could not verify LD-Signature for #{value_or_id(@json['actor'])}: #{e.message}" }
nil
end
end

+ 1
- 1
app/services/activitypub/process_status_update_service.rb View File

@ -94,7 +94,7 @@ class ActivityPub::ProcessStatusUpdateService < BaseService
@next_media_attachments << media_attachment
rescue Addressable::URI::InvalidURIError => e
Rails.logger.debug "Invalid URL in attachment: #{e}"
Rails.logger.debug { "Invalid URL in attachment: #{e}" }
end
end

+ 1
- 1
app/services/fetch_link_card_service.rb View File

@ -30,7 +30,7 @@ class FetchLinkCardService < BaseService
attach_card if @card&.persisted?
rescue HTTP::Error, OpenSSL::SSL::SSLError, Addressable::URI::InvalidURIError, Mastodon::HostValidationError, Mastodon::LengthValidationError => e
Rails.logger.debug "Error fetching link #{@original_url}: #{e}"
Rails.logger.debug { "Error fetching link #{@original_url}: #{e}" }
nil
end

+ 1
- 1
app/services/fetch_resource_service.rb View File

@ -12,7 +12,7 @@ class FetchResourceService < BaseService
process(url)
rescue HTTP::Error, OpenSSL::SSL::SSLError, Addressable::URI::InvalidURIError, Mastodon::HostValidationError, Mastodon::LengthValidationError => e
Rails.logger.debug "Error fetching resource #{@url}: #{e}"
Rails.logger.debug { "Error fetching resource #{@url}: #{e}" }
nil
end

+ 1
- 1
app/services/keys/claim_service.rb View File

@ -58,7 +58,7 @@ class Keys::ClaimService < BaseService
@result = Result.new(@target_account, @device_id, key_id: json['id'], key: json['publicKeyBase64'], signature: json.dig('signature', 'signatureValue'))
rescue HTTP::Error, OpenSSL::SSL::SSLError, Mastodon::Error => e
Rails.logger.debug "Claiming one-time key for #{@target_account.acct}:#{@device_id} failed: #{e}"
Rails.logger.debug { "Claiming one-time key for #{@target_account.acct}:#{@device_id} failed: #{e}" }
nil
end

+ 1
- 1
app/services/keys/query_service.rb View File

@ -73,7 +73,7 @@ class Keys::QueryService < BaseService
Device.new(device_id: device['id'], name: device['name'], identity_key: device.dig('identityKey', 'publicKeyBase64'), fingerprint_key: device.dig('fingerprintKey', 'publicKeyBase64'), claim_url: device['claim'])
end
rescue HTTP::Error, OpenSSL::SSL::SSLError, Mastodon::Error => e
Rails.logger.debug "Querying devices for #{@account.acct} failed: #{e}"
Rails.logger.debug { "Querying devices for #{@account.acct} failed: #{e}" }
nil
end
end

+ 1
- 1
app/services/resolve_account_service.rb View File

@ -54,7 +54,7 @@ class ResolveAccountService < BaseService
fetch_account!
rescue Webfinger::Error => e
Rails.logger.debug "Webfinger query for #{@uri} failed: #{e}"
Rails.logger.debug { "Webfinger query for #{@uri} failed: #{e}" }
raise unless @options[:suppress_errors]
end

+ 1
- 1
app/services/verify_link_service.rb View File

@ -11,7 +11,7 @@ class VerifyLinkService < BaseService
field.mark_verified!
rescue OpenSSL::SSL::SSLError, HTTP::Error, Addressable::URI::InvalidURIError, Mastodon::HostValidationError, Mastodon::LengthValidationError, IPAddr::AddressFamilyError => e
Rails.logger.debug "Error fetching link #{@url}: #{e}"
Rails.logger.debug { "Error fetching link #{@url}: #{e}" }
nil
end

+ 1
- 1
app/workers/activitypub/processing_worker.rb View File

@ -15,6 +15,6 @@ class ActivityPub::ProcessingWorker
ActivityPub::ProcessCollectionService.new.call(body, actor, override_timestamps: true, delivered_to_account_id: delivered_to_account_id, delivery: true)
rescue ActiveRecord::RecordInvalid => e
Rails.logger.debug "Error processing incoming ActivityPub object: #{e}"
Rails.logger.debug { "Error processing incoming ActivityPub object: #{e}" }
end
end

+ 3
- 1
spec/models/concerns/remotable_spec.rb View File

@ -194,7 +194,9 @@ RSpec.describe Remotable do
let(:error_class) { error_class }
it 'calls Rails.logger.debug' do
expect(Rails.logger).to receive(:debug).with(/^Error fetching remote #{hoge}: /)
expect(Rails.logger).to receive(:debug) do |&block|
expect(block.call).to match(/^Error fetching remote #{hoge}: /)
end
foo.hoge_remote_url = url
end
end

Loading…
Cancel
Save