Browse Source

Convert NullReferenceException to ResourceNotFoundException

crobibero 4 years ago
parent
commit
5f52a58e78

+ 3 - 2
Emby.Server.Implementations/AppBase/ConfigurationHelper.cs

@@ -3,6 +3,7 @@
 using System;
 using System.IO;
 using System.Linq;
+using MediaBrowser.Common.Extensions;
 using MediaBrowser.Model.Serialization;
 
 namespace Emby.Server.Implementations.AppBase
@@ -36,7 +37,7 @@ namespace Emby.Server.Implementations.AppBase
             catch (Exception)
             {
                 var instanceConfiguration = Activator.CreateInstance(type);
-                configuration = instanceConfiguration ?? throw new NullReferenceException(nameof(instanceConfiguration));
+                configuration = instanceConfiguration ?? throw new ResourceNotFoundException(nameof(instanceConfiguration));
             }
 
             using var stream = new MemoryStream(buffer?.Length ?? 0);
@@ -52,7 +53,7 @@ namespace Emby.Server.Implementations.AppBase
                 var directory = Path.GetDirectoryName(path);
                 if (directory == null)
                 {
-                    throw new NullReferenceException(nameof(directory));
+                    throw new ResourceNotFoundException(nameof(directory));
                 }
 
                 Directory.CreateDirectory(directory);

+ 2 - 1
Emby.Server.Implementations/Cryptography/CryptographyProvider.cs

@@ -3,6 +3,7 @@
 using System;
 using System.Collections.Generic;
 using System.Security.Cryptography;
+using MediaBrowser.Common.Extensions;
 using MediaBrowser.Model.Cryptography;
 using static MediaBrowser.Common.Cryptography.Constants;
 
@@ -83,7 +84,7 @@ namespace Emby.Server.Implementations.Cryptography
             using var h = HashAlgorithm.Create(hashMethod);
             if (h == null)
             {
-                throw new NullReferenceException(nameof(h));
+                throw new ResourceNotFoundException(nameof(h));
             }
 
             if (salt.Length == 0)

+ 2 - 1
Emby.Server.Implementations/Session/WebSocketController.cs

@@ -8,6 +8,7 @@ using System.Linq;
 using System.Net.WebSockets;
 using System.Threading;
 using System.Threading.Tasks;
+using MediaBrowser.Common.Extensions;
 using MediaBrowser.Controller.Net;
 using MediaBrowser.Controller.Session;
 using MediaBrowser.Model.Net;
@@ -59,7 +60,7 @@ namespace Emby.Server.Implementations.Session
         {
             if (sender == null)
             {
-                throw new NullReferenceException(nameof(sender));
+                throw new ResourceNotFoundException(nameof(sender));
             }
 
             var connection = (IWebSocketConnection)sender;

+ 3 - 2
Jellyfin.Api/Controllers/DynamicHlsController.cs

@@ -14,6 +14,7 @@ using Jellyfin.Api.Helpers;
 using Jellyfin.Api.Models.PlaybackDtos;
 using Jellyfin.Api.Models.StreamingDtos;
 using MediaBrowser.Common.Configuration;
+using MediaBrowser.Common.Extensions;
 using MediaBrowser.Controller.Configuration;
 using MediaBrowser.Controller.Devices;
 using MediaBrowser.Controller.Dlna;
@@ -1350,7 +1351,7 @@ namespace Jellyfin.Api.Controllers
             var directory = Path.GetDirectoryName(outputPath);
             if (directory == null)
             {
-                throw new NullReferenceException(nameof(directory));
+                throw new ResourceNotFoundException(nameof(directory));
             }
 
             var outputTsArg = Path.Combine(directory, Path.GetFileNameWithoutExtension(outputPath)) + "%d" + GetSegmentFileExtension(state.Request.SegmentContainer);
@@ -1574,7 +1575,7 @@ namespace Jellyfin.Api.Controllers
             var folder = Path.GetDirectoryName(playlist);
             if (folder == null)
             {
-                throw new NullReferenceException(nameof(folder));
+                throw new ResourceNotFoundException(nameof(folder));
             }
 
             var filename = Path.GetFileNameWithoutExtension(playlist);

+ 2 - 1
Jellyfin.Api/Controllers/EnvironmentController.cs

@@ -5,6 +5,7 @@ using System.IO;
 using System.Linq;
 using Jellyfin.Api.Constants;
 using Jellyfin.Api.Models.EnvironmentDtos;
+using MediaBrowser.Common.Extensions;
 using MediaBrowser.Model.IO;
 using Microsoft.AspNetCore.Authorization;
 using Microsoft.AspNetCore.Http;
@@ -105,7 +106,7 @@ namespace Jellyfin.Api.Controllers
                 {
                     if (validatePathDto.Path == null)
                     {
-                        throw new NullReferenceException(nameof(validatePathDto.Path));
+                        throw new ResourceNotFoundException(nameof(validatePathDto.Path));
                     }
 
                     var file = Path.Combine(validatePathDto.Path, Guid.NewGuid().ToString());

+ 2 - 1
Jellyfin.Api/Controllers/HlsSegmentController.cs

@@ -8,6 +8,7 @@ using Jellyfin.Api.Attributes;
 using Jellyfin.Api.Constants;
 using Jellyfin.Api.Helpers;
 using MediaBrowser.Common.Configuration;
+using MediaBrowser.Common.Extensions;
 using MediaBrowser.Controller.Configuration;
 using MediaBrowser.Controller.MediaEncoding;
 using MediaBrowser.Model.IO;
@@ -138,7 +139,7 @@ namespace Jellyfin.Api.Controllers
 
             if (playlistPath == null)
             {
-                throw new NullReferenceException(nameof(playlistPath));
+                throw new ResourceNotFoundException(nameof(playlistPath));
             }
 
             return GetFileResult(file, playlistPath);

+ 3 - 3
Jellyfin.Api/Controllers/ItemLookupController.cs

@@ -336,7 +336,7 @@ namespace Jellyfin.Api.Controllers
             using var result = await _providerManager.GetSearchImage(providerName, url, CancellationToken.None).ConfigureAwait(false);
             if (result.Content.Headers.ContentType?.MediaType == null)
             {
-                throw new NullReferenceException(nameof(result.Content.Headers.ContentType));
+                throw new ResourceNotFoundException(nameof(result.Content.Headers.ContentType));
             }
 
             var ext = result.Content.Headers.ContentType.MediaType.Split('/')[^1];
@@ -345,7 +345,7 @@ namespace Jellyfin.Api.Controllers
             var directory = Path.GetDirectoryName(fullCachePath);
             if (directory == null)
             {
-                throw new NullReferenceException(nameof(directory));
+                throw new ResourceNotFoundException(nameof(directory));
             }
 
             Directory.CreateDirectory(directory);
@@ -365,7 +365,7 @@ namespace Jellyfin.Api.Controllers
             var pointerCacheDirectory = Path.GetDirectoryName(pointerCachePath);
             if (pointerCacheDirectory == null)
             {
-                throw new NullReferenceException(nameof(pointerCacheDirectory));
+                throw new ResourceNotFoundException(nameof(pointerCacheDirectory));
             }
 
             Directory.CreateDirectory(pointerCacheDirectory);

+ 3 - 3
Jellyfin.Api/Controllers/RemoteImageController.cs

@@ -251,7 +251,7 @@ namespace Jellyfin.Api.Controllers
             using var response = await httpClient.GetAsync(url).ConfigureAwait(false);
             if (response.Content.Headers.ContentType?.MediaType == null)
             {
-                throw new NullReferenceException(nameof(response.Content.Headers.ContentType));
+                throw new ResourceNotFoundException(nameof(response.Content.Headers.ContentType));
             }
 
             var ext = response.Content.Headers.ContentType.MediaType.Split('/').Last();
@@ -260,7 +260,7 @@ namespace Jellyfin.Api.Controllers
             var fullCacheDirectory = Path.GetDirectoryName(fullCachePath);
             if (fullCacheDirectory == null)
             {
-                throw new NullReferenceException(nameof(fullCacheDirectory));
+                throw new ResourceNotFoundException(nameof(fullCacheDirectory));
             }
 
             Directory.CreateDirectory(fullCacheDirectory);
@@ -270,7 +270,7 @@ namespace Jellyfin.Api.Controllers
             var pointerCacheDirectory = Path.GetDirectoryName(pointerCachePath);
             if (pointerCacheDirectory == null)
             {
-                throw new NullReferenceException(nameof(pointerCacheDirectory));
+                throw new ResourceNotFoundException(nameof(pointerCacheDirectory));
             }
 
             Directory.CreateDirectory(pointerCacheDirectory);

+ 2 - 1
Jellyfin.Api/Controllers/VideoHlsController.cs

@@ -11,6 +11,7 @@ using Jellyfin.Api.Helpers;
 using Jellyfin.Api.Models.PlaybackDtos;
 using Jellyfin.Api.Models.StreamingDtos;
 using MediaBrowser.Common.Configuration;
+using MediaBrowser.Common.Extensions;
 using MediaBrowser.Controller.Configuration;
 using MediaBrowser.Controller.Devices;
 using MediaBrowser.Controller.Dlna;
@@ -364,7 +365,7 @@ namespace Jellyfin.Api.Controllers
             var directory = Path.GetDirectoryName(outputPath);
             if (directory == null)
             {
-                throw new NullReferenceException(nameof(directory));
+                throw new ResourceNotFoundException(nameof(directory));
             }
 
             var outputTsArg = Path.Combine(directory, Path.GetFileNameWithoutExtension(outputPath)) + "%d" + format;

+ 2 - 1
Jellyfin.Api/Helpers/AudioHelper.cs

@@ -4,6 +4,7 @@ using System.Threading;
 using System.Threading.Tasks;
 using Jellyfin.Api.Models.StreamingDtos;
 using MediaBrowser.Common.Configuration;
+using MediaBrowser.Common.Extensions;
 using MediaBrowser.Common.Net;
 using MediaBrowser.Controller.Configuration;
 using MediaBrowser.Controller.Devices;
@@ -101,7 +102,7 @@ namespace Jellyfin.Api.Helpers
         {
             if (_httpContextAccessor.HttpContext == null)
             {
-                throw new NullReferenceException(nameof(_httpContextAccessor.HttpContext));
+                throw new ResourceNotFoundException(nameof(_httpContextAccessor.HttpContext));
             }
 
             bool isHeadRequest = _httpContextAccessor.HttpContext.Request.Method == System.Net.WebRequestMethods.Http.Head;

+ 1 - 1
Jellyfin.Api/Helpers/DynamicHlsHelper.cs

@@ -132,7 +132,7 @@ namespace Jellyfin.Api.Helpers
         {
             if (_httpContextAccessor.HttpContext == null)
             {
-                throw new NullReferenceException(nameof(_httpContextAccessor.HttpContext));
+                throw new ResourceNotFoundException(nameof(_httpContextAccessor.HttpContext));
             }
 
             using var state = await StreamingHelpers.GetStreamingState(

+ 2 - 1
Jellyfin.Api/Helpers/HlsHelpers.cs

@@ -3,6 +3,7 @@ using System.Globalization;
 using System.IO;
 using System.Threading;
 using System.Threading.Tasks;
+using MediaBrowser.Common.Extensions;
 using MediaBrowser.Model.IO;
 using Microsoft.Extensions.Logging;
 
@@ -47,7 +48,7 @@ namespace Jellyfin.Api.Helpers
                             var line = await reader.ReadLineAsync().ConfigureAwait(false);
                             if (line == null)
                             {
-                                throw new NullReferenceException(nameof(line));
+                                throw new ResourceNotFoundException(nameof(line));
                             }
 
                             if (line.IndexOf("#EXTINF:", StringComparison.OrdinalIgnoreCase) != -1)

+ 2 - 1
Jellyfin.Api/Helpers/ProgressiveFileCopier.cs

@@ -5,6 +5,7 @@ using System.Runtime.InteropServices;
 using System.Threading;
 using System.Threading.Tasks;
 using Jellyfin.Api.Models.PlaybackDtos;
+using MediaBrowser.Common.Extensions;
 using MediaBrowser.Controller.Library;
 using MediaBrowser.Model.IO;
 
@@ -92,7 +93,7 @@ namespace Jellyfin.Api.Helpers
 
                 if (_path == null)
                 {
-                    throw new NullReferenceException(nameof(_path));
+                    throw new ResourceNotFoundException(nameof(_path));
                 }
 
                 await using var inputStream = new FileStream(_path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite, IODefaults.FileStreamBufferSize, fileOptions);

+ 1 - 1
Jellyfin.Api/Helpers/StreamingHelpers.cs

@@ -85,7 +85,7 @@ namespace Jellyfin.Api.Helpers
             streamingRequest.StreamOptions = ParseStreamOptions(httpRequest.Query);
             if (httpRequest.Path.Value == null)
             {
-                throw new NullReferenceException(nameof(httpRequest.Path));
+                throw new ResourceNotFoundException(nameof(httpRequest.Path));
             }
 
             var url = httpRequest.Path.Value.Split('.').Last();

+ 3 - 2
Jellyfin.Api/Helpers/TranscodingJobHelper.cs

@@ -12,6 +12,7 @@ using Jellyfin.Api.Models.PlaybackDtos;
 using Jellyfin.Api.Models.StreamingDtos;
 using Jellyfin.Data.Enums;
 using MediaBrowser.Common.Configuration;
+using MediaBrowser.Common.Extensions;
 using MediaBrowser.Controller.Configuration;
 using MediaBrowser.Controller.Library;
 using MediaBrowser.Controller.MediaEncoding;
@@ -198,7 +199,7 @@ namespace Jellyfin.Api.Helpers
             var job = (TranscodingJobDto?)state;
             if (job == null)
             {
-                throw new NullReferenceException(nameof(job));
+                throw new ResourceNotFoundException(nameof(job));
             }
 
             if (!job.HasExited && job.Type != TranscodingJobType.Progressive)
@@ -496,7 +497,7 @@ namespace Jellyfin.Api.Helpers
             var directory = Path.GetDirectoryName(outputPath);
             if (directory == null)
             {
-                throw new NullReferenceException(nameof(directory));
+                throw new ResourceNotFoundException(nameof(directory));
             }
 
             Directory.CreateDirectory(directory);

+ 4 - 3
Jellyfin.Drawing.Skia/SkiaEncoder.cs

@@ -4,6 +4,7 @@ using System.Globalization;
 using System.IO;
 using BlurHashSharp.SkiaSharp;
 using MediaBrowser.Common.Configuration;
+using MediaBrowser.Common.Extensions;
 using MediaBrowser.Controller.Drawing;
 using MediaBrowser.Controller.Extensions;
 using MediaBrowser.Model.Drawing;
@@ -230,7 +231,7 @@ namespace Jellyfin.Drawing.Skia
             var directory = Path.GetDirectoryName(tempPath);
             if (directory == null)
             {
-                throw new NullReferenceException(nameof(directory));
+                throw new ResourceNotFoundException(nameof(directory));
             }
 
             Directory.CreateDirectory(directory);
@@ -501,7 +502,7 @@ namespace Jellyfin.Drawing.Skia
                 var outputDirectory = Path.GetDirectoryName(outputPath);
                 if (outputDirectory == null)
                 {
-                    throw new NullReferenceException(nameof(outputDirectory));
+                    throw new ResourceNotFoundException(nameof(outputDirectory));
                 }
 
                 Directory.CreateDirectory(outputDirectory);
@@ -554,7 +555,7 @@ namespace Jellyfin.Drawing.Skia
             var directory = Path.GetDirectoryName(outputPath);
             if (directory == null)
             {
-                throw new NullReferenceException(nameof(directory));
+                throw new ResourceNotFoundException(nameof(directory));
             }
 
             Directory.CreateDirectory(directory);

+ 1 - 1
Jellyfin.Server.Implementations/Users/DefaultPasswordResetProvider.cs

@@ -62,7 +62,7 @@ namespace Jellyfin.Server.Implementations.Users
 
                 if (spr == null)
                 {
-                    throw new NullReferenceException(nameof(spr));
+                    throw new ResourceNotFoundException(nameof(spr));
                 }
 
                 if (spr.ExpirationDate < DateTime.UtcNow)

+ 2 - 1
MediaBrowser.LocalMetadata/Savers/BaseXmlSaver.cs

@@ -5,6 +5,7 @@ using System.Linq;
 using System.Text;
 using System.Threading;
 using System.Xml;
+using MediaBrowser.Common.Extensions;
 using MediaBrowser.Controller.Configuration;
 using MediaBrowser.Controller.Entities;
 using MediaBrowser.Controller.Entities.Movies;
@@ -130,7 +131,7 @@ namespace MediaBrowser.LocalMetadata.Savers
             var directory = Path.GetDirectoryName(path);
             if (directory == null)
             {
-                throw new NullReferenceException(nameof(directory));
+                throw new ResourceNotFoundException(nameof(directory));
             }
 
             Directory.CreateDirectory(directory);