The Free Software Media System - Server Backend & API
Don't allow throwing System.Exception (#8378)
Bond-0092d57e71b4446
diff --git a/Emby.Server.Implementations/LiveTv/EmbyTV/EmbyTV.cs b/Emby.Server.Implementations/LiveTv/EmbyTV/EmbyTV.csindex 2753cf1778..065309688c 100644--- a/Emby.Server.Implementations/LiveTv/EmbyTV/EmbyTV.cs+++ b/Emby.Server.Implementations/LiveTv/EmbyTV/EmbyTV.cs@@ -995,7 +995,7 @@ namespace Emby.Server.Implementations.LiveTv.EmbyTV}}- throw new Exception("Tuner not found.");+ throw new ResourceNotFoundException("Tuner not found.");}public async Task<List<MediaSourceInfo>> GetChannelStreamMediaSources(string channelId, CancellationToken cancellationToken)diff --git a/Emby.Server.Implementations/LiveTv/EmbyTV/EncodedRecorder.cs b/Emby.Server.Implementations/LiveTv/EmbyTV/EncodedRecorder.csindex 6e05598410..08534de59d 100644--- a/Emby.Server.Implementations/LiveTv/EmbyTV/EncodedRecorder.cs+++ b/Emby.Server.Implementations/LiveTv/EmbyTV/EncodedRecorder.cs@@ -13,6 +13,7 @@ using System.Threading;using System.Threading.Tasks;using Jellyfin.Extensions;using Jellyfin.Extensions.Json;+using MediaBrowser.Common;using MediaBrowser.Common.Configuration;using MediaBrowser.Controller;using MediaBrowser.Controller.Configuration;@@ -297,7 +298,7 @@ namespace Emby.Server.Implementations.LiveTv.EmbyTVelse{_taskCompletionSource.TrySetException(- new Exception(+ new FfmpegException(string.Format(CultureInfo.InvariantCulture,"Recording for {0} failed. Exit code {1}",diff --git a/Emby.Server.Implementations/LiveTv/Listings/SchedulesDirect.cs b/Emby.Server.Implementations/LiveTv/Listings/SchedulesDirect.csindex ffa0d9b6a0..4311db28d2 100644--- a/Emby.Server.Implementations/LiveTv/Listings/SchedulesDirect.cs+++ b/Emby.Server.Implementations/LiveTv/Listings/SchedulesDirect.cs@@ -20,6 +20,7 @@ using Emby.Server.Implementations.LiveTv.Listings.SchedulesDirectDtos;using Jellyfin.Extensions;using Jellyfin.Extensions.Json;using MediaBrowser.Common.Net;+using MediaBrowser.Controller.Authentication;using MediaBrowser.Controller.LiveTv;using MediaBrowser.Model.Dto;using MediaBrowser.Model.Entities;@@ -591,13 +592,10 @@ namespace Emby.Server.Implementations.LiveTv.Listings}catch (HttpRequestException ex){- if (ex.StatusCode.HasValue)+ if (ex.StatusCode.HasValue && ex.StatusCode.Value == HttpStatusCode.BadRequest){- if ((int)ex.StatusCode.Value == 400)- {- _tokens.Clear();- _lastErrorResponse = DateTime.UtcNow;- }+ _tokens.Clear();+ _lastErrorResponse = DateTime.UtcNow;}throw;@@ -662,7 +660,7 @@ namespace Emby.Server.Implementations.LiveTv.Listingsreturn root.Token;}- throw new Exception("Could not authenticate with Schedules Direct Error: " + root.Message);+ throw new AuthenticationException("Could not authenticate with Schedules Direct Error: " + root.Message);}private async Task AddLineupToAccount(ListingsProviderInfo info, CancellationToken cancellationToken)@@ -697,7 +695,7 @@ namespace Emby.Server.Implementations.LiveTv.Listingsif (string.IsNullOrEmpty(token)){- throw new Exception("token required");+ throw new ArgumentException("token required");}_logger.LogInformation("Headends on account ");@@ -768,14 +766,14 @@ namespace Emby.Server.Implementations.LiveTv.Listingsvar listingsId = info.ListingsId;if (string.IsNullOrEmpty(listingsId)){- throw new Exception("ListingsId required");+ throw new ArgumentException("ListingsId required");}var token = await GetToken(info, cancellationToken).ConfigureAwait(false);if (string.IsNullOrEmpty(token)){- throw new Exception("token required");+ throw new ArgumentException("token required");}using var options = new HttpRequestMessage(HttpMethod.Get, ApiUrl + "/lineups/" + listingsId);diff --git a/Emby.Server.Implementations/Net/UdpSocket.cs b/Emby.Server.Implementations/Net/UdpSocket.csindex bbbca4fc08..2c20daa57f 100644--- a/Emby.Server.Implementations/Net/UdpSocket.cs+++ b/Emby.Server.Implementations/Net/UdpSocket.cs@@ -96,7 +96,7 @@ namespace Emby.Server.Implementations.Net}else{- tcs.TrySetException(new Exception("SocketError: " + e.SocketError));+ tcs.TrySetException(new SocketException((int)e.SocketError));}}}@@ -114,7 +114,7 @@ namespace Emby.Server.Implementations.Net}else{- tcs.TrySetException(new Exception("SocketError: " + e.SocketError));+ tcs.TrySetException(new SocketException((int)e.SocketError));}}}diff --git a/jellyfin.ruleset b/jellyfin.rulesetindex 1c834de822..5ac5f49239 100644--- a/jellyfin.ruleset+++ b/jellyfin.ruleset@@ -84,6 +84,8 @@<!-- error on CA2016: Forward the CancellationToken parameter to methods that take oneor pass in 'CancellationToken.None' explicitly to indicate intentionally not propagating the token --><Rule Id="CA2016" Action="Error" />+ <!-- error on CA2201: Exception type System.Exception is not sufficiently specific -->+ <Rule Id="CA2201" Action="Error" /><!-- error on CA2215: Dispose methods should call base class dispose --><Rule Id="CA2215" Action="Error" /><!-- error on CA2254: Template should be a static expression -->