diff options
| author | Bond-009 <bond.009@outlook.com> | 2022-09-12 01:56:41 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-09-11 17:56:41 -0600 |
| commit | 2d57e71b4446df7274ae3a9bc45421f890c1bdd2 (patch) | |
| tree | 068ffd01de5f027f914c3adb96ece9b50af73240 | |
| parent | d2e18547b16fa30684d7c9ceb8a117d5d9bcef56 (diff) | |
Don't allow throwing System.Exception (#8378)
| -rw-r--r-- | Emby.Server.Implementations/LiveTv/EmbyTV/EmbyTV.cs | 2 | ||||
| -rw-r--r-- | Emby.Server.Implementations/LiveTv/EmbyTV/EncodedRecorder.cs | 3 | ||||
| -rw-r--r-- | Emby.Server.Implementations/LiveTv/Listings/SchedulesDirect.cs | 18 | ||||
| -rw-r--r-- | Emby.Server.Implementations/Net/UdpSocket.cs | 4 | ||||
| -rw-r--r-- | jellyfin.ruleset | 2 |
5 files changed, 15 insertions, 14 deletions
diff --git a/Emby.Server.Implementations/LiveTv/EmbyTV/EmbyTV.cs b/Emby.Server.Implementations/LiveTv/EmbyTV/EmbyTV.cs index 2753cf177..065309688 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.cs index 6e0559841..08534de59 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.EmbyTV else { _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.cs index ffa0d9b6a..4311db28d 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.Listings return 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.Listings if (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.Listings var 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.cs index bbbca4fc0..2c20daa57 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.ruleset index 1c834de82..5ac5f4923 100644 --- a/jellyfin.ruleset +++ b/jellyfin.ruleset @@ -84,6 +84,8 @@ <!-- error on CA2016: Forward the CancellationToken parameter to methods that take one or 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 --> |
