From a714587002b5678917b655692793c1ea88a22cc4 Mon Sep 17 00:00:00 2001 From: Matt Jankowski Date: Wed, 30 Oct 2024 15:46:46 -0400 Subject: [PATCH] Rename error classes --- app/controllers/activitypub/inboxes_controller.rb | 2 +- app/helpers/jsonld_helper.rb | 2 +- app/lib/admin/metrics/dimension/software_versions_dimension.rb | 2 +- app/lib/link_details_extractor.rb | 2 +- app/lib/translation_service/deepl.rb | 2 +- app/lib/translation_service/libre_translate.rb | 2 +- app/lib/video_metadata_extractor.rb | 2 +- app/lib/webfinger.rb | 2 +- app/services/activitypub/fetch_remote_actor_service.rb | 2 +- app/services/activitypub/process_account_service.rb | 2 +- app/services/activitypub/process_collection_service.rb | 2 +- app/services/fetch_oembed_service.rb | 2 +- app/services/software_update_check_service.rb | 2 +- 13 files changed, 13 insertions(+), 13 deletions(-) diff --git a/app/controllers/activitypub/inboxes_controller.rb b/app/controllers/activitypub/inboxes_controller.rb index 43a640501c..fc153a63ba 100644 --- a/app/controllers/activitypub/inboxes_controller.rb +++ b/app/controllers/activitypub/inboxes_controller.rb @@ -23,7 +23,7 @@ class ActivityPub::InboxesController < ActivityPub::BaseController def unknown_affected_account? json = JSON.parse(body) json.is_a?(Hash) && %w(Delete Update).include?(json['type']) && json['actor'].present? && json['actor'] == value_or_id(json['object']) && !Account.exists?(uri: json['actor']) - rescue Oj::ParseError + rescue JSON::ParserError false end diff --git a/app/helpers/jsonld_helper.rb b/app/helpers/jsonld_helper.rb index 45762abf2a..9c10cc23c7 100644 --- a/app/helpers/jsonld_helper.rb +++ b/app/helpers/jsonld_helper.rb @@ -196,7 +196,7 @@ module JsonLdHelper return if compare_id.present? && json['id'] != compare_id json - rescue Oj::ParseError + rescue JSON::ParserError nil end diff --git a/app/lib/admin/metrics/dimension/software_versions_dimension.rb b/app/lib/admin/metrics/dimension/software_versions_dimension.rb index bd79e25c9e..d4f25a4bf7 100644 --- a/app/lib/admin/metrics/dimension/software_versions_dimension.rb +++ b/app/lib/admin/metrics/dimension/software_versions_dimension.rb @@ -114,7 +114,7 @@ class Admin::Metrics::Dimension::SoftwareVersionsDimension < Admin::Metrics::Dim value: version, human_value: version, } - rescue Terrapin::CommandNotFoundError, Terrapin::ExitStatusError, Oj::ParseError + rescue Terrapin::CommandNotFoundError, Terrapin::ExitStatusError, JSON::ParserError nil end diff --git a/app/lib/link_details_extractor.rb b/app/lib/link_details_extractor.rb index 91729e55df..5fd28d9468 100644 --- a/app/lib/link_details_extractor.rb +++ b/app/lib/link_details_extractor.rb @@ -265,7 +265,7 @@ class LinkDetailsExtractor next unless structured_data.valid? structured_data - rescue Oj::ParseError, EncodingError + rescue JSON::ParserError, EncodingError Rails.logger.debug { "Invalid JSON-LD in #{@original_url}" } next end.first diff --git a/app/lib/translation_service/deepl.rb b/app/lib/translation_service/deepl.rb index 59c255a7ce..98536fe2de 100644 --- a/app/lib/translation_service/deepl.rb +++ b/app/lib/translation_service/deepl.rb @@ -78,7 +78,7 @@ class TranslationService::DeepL < TranslationService provider: 'DeepL.com' ) end - rescue Oj::ParseError + rescue JSON::ParserError raise UnexpectedResponseError end end diff --git a/app/lib/translation_service/libre_translate.rb b/app/lib/translation_service/libre_translate.rb index 8d6472c215..817af7d991 100644 --- a/app/lib/translation_service/libre_translate.rb +++ b/app/lib/translation_service/libre_translate.rb @@ -55,7 +55,7 @@ class TranslationService::LibreTranslate < TranslationService provider: 'LibreTranslate' ) end - rescue Oj::ParseError + rescue JSON::ParserError raise UnexpectedResponseError end end diff --git a/app/lib/video_metadata_extractor.rb b/app/lib/video_metadata_extractor.rb index 66f4c1b772..f94df7cf58 100644 --- a/app/lib/video_metadata_extractor.rb +++ b/app/lib/video_metadata_extractor.rb @@ -9,7 +9,7 @@ class VideoMetadataExtractor @metadata = JSON.parse(ffmpeg_command_output, symbolize_names: true) parse_metadata - rescue Terrapin::ExitStatusError, Oj::ParseError + rescue Terrapin::ExitStatusError, JSON::ParserError @invalid = true rescue Terrapin::CommandNotFoundError raise Paperclip::Errors::CommandNotFoundError, 'Could not run the `ffprobe` command. Please install ffmpeg.' diff --git a/app/lib/webfinger.rb b/app/lib/webfinger.rb index 6e13d2f163..4a978c5921 100644 --- a/app/lib/webfinger.rb +++ b/app/lib/webfinger.rb @@ -57,7 +57,7 @@ class Webfinger def perform Response.new(@uri, body_from_webfinger) - rescue Oj::ParseError + rescue JSON::ParserError raise Webfinger::Error, "Invalid JSON in response for #{@uri}" rescue Addressable::URI::InvalidURIError raise Webfinger::Error, "Invalid URI for #{@uri}" diff --git a/app/services/activitypub/fetch_remote_actor_service.rb b/app/services/activitypub/fetch_remote_actor_service.rb index 560cf424e1..1fb3f45ce5 100644 --- a/app/services/activitypub/fetch_remote_actor_service.rb +++ b/app/services/activitypub/fetch_remote_actor_service.rb @@ -19,7 +19,7 @@ class ActivityPub::FetchRemoteActorService < BaseService else body_to_json(prefetched_body, compare_id: uri) end - rescue Oj::ParseError + rescue JSON::ParserError raise Error, "Error parsing JSON-LD document #{uri}" end diff --git a/app/services/activitypub/process_account_service.rb b/app/services/activitypub/process_account_service.rb index df6f23c021..97c7f11a3a 100644 --- a/app/services/activitypub/process_account_service.rb +++ b/app/services/activitypub/process_account_service.rb @@ -61,7 +61,7 @@ class ActivityPub::ProcessAccountService < BaseService end @account - rescue Oj::ParseError + rescue JSON::ParserError nil end diff --git a/app/services/activitypub/process_collection_service.rb b/app/services/activitypub/process_collection_service.rb index d9ba5d5822..2b5043dc66 100644 --- a/app/services/activitypub/process_collection_service.rb +++ b/app/services/activitypub/process_collection_service.rb @@ -38,7 +38,7 @@ class ActivityPub::ProcessCollectionService < BaseService else process_items [@json] end - rescue Oj::ParseError + rescue JSON::ParserError nil end diff --git a/app/services/fetch_oembed_service.rb b/app/services/fetch_oembed_service.rb index c2887e3017..cc71a5f92b 100644 --- a/app/services/fetch_oembed_service.rb +++ b/app/services/fetch_oembed_service.rb @@ -86,7 +86,7 @@ class FetchOEmbedService end validate(parse_for_format(body)) if body.present? - rescue Oj::ParseError, Ox::ParseError + rescue JSON::ParserError, Ox::ParseError nil end diff --git a/app/services/software_update_check_service.rb b/app/services/software_update_check_service.rb index e3bc112964..aa2eadd94c 100644 --- a/app/services/software_update_check_service.rb +++ b/app/services/software_update_check_service.rb @@ -22,7 +22,7 @@ class SoftwareUpdateCheckService < BaseService Request.new(:get, "#{api_url}?version=#{version}").add_headers('Accept' => 'application/json', 'User-Agent' => 'Mastodon update checker').perform do |res| return JSON.parse(res.body_with_limit) if res.code == 200 end - rescue *Mastodon::HTTP_CONNECTION_ERRORS, Oj::ParseError + rescue *Mastodon::HTTP_CONNECTION_ERRORS, JSON::ParserError nil end