From 79d18cf5a5fde7594eb17247f920a54d8978a81c Mon Sep 17 00:00:00 2001 From: Bond_009 Date: Thu, 20 Dec 2018 13:39:58 +0100 Subject: [PATCH] Clean up some catch statements --- Emby.Dlna/Didl/DidlBuilder.cs | 4 +- Emby.Dlna/DlnaManager.cs | 4 +- Emby.Dlna/PlayTo/Device.cs | 4 +- .../ImageMagickEncoder.cs | 4 +- Emby.Drawing/ImageProcessor.cs | 10 +-- .../IsoMounter/LinuxIsoManager.cs | 72 ++++++++----------- .../ApplicationHost.cs | 2 +- Emby.Server.Implementations/Dto/DtoService.cs | 2 +- .../EntryPoints/ExternalPortForwarding.cs | 1 + .../IO/SharpCifs/Config.cs | 2 +- .../IO/SharpCifs/Dcerpc/DcerpcHandle.cs | 2 +- .../IO/SharpCifs/Netbios/Name.cs | 2 +- .../IO/SharpCifs/Netbios/NameServiceClient.cs | 8 ++- .../IO/SharpCifs/Smb/NtlmContext.cs | 2 +- 14 files changed, 56 insertions(+), 63 deletions(-) diff --git a/Emby.Dlna/Didl/DidlBuilder.cs b/Emby.Dlna/Didl/DidlBuilder.cs index 6de35b842..7af48ae17 100644 --- a/Emby.Dlna/Didl/DidlBuilder.cs +++ b/Emby.Dlna/Didl/DidlBuilder.cs @@ -1070,9 +1070,9 @@ namespace Emby.Dlna.Didl { tag = _imageProcessor.GetImageCacheTag(item, type); } - catch + catch (Exception ex) { - + _logger.LogError(ex, "Error getting image cache tag"); } int? width = imageInfo.Width; diff --git a/Emby.Dlna/DlnaManager.cs b/Emby.Dlna/DlnaManager.cs index eae4f3271..48a33757b 100644 --- a/Emby.Dlna/DlnaManager.cs +++ b/Emby.Dlna/DlnaManager.cs @@ -198,7 +198,7 @@ namespace Emby.Dlna } catch (ArgumentException ex) { - _logger.LogError(ex, "Error evaluating regex pattern {0}", pattern); + _logger.LogError(ex, "Error evaluating regex pattern {Pattern}", pattern); return false; } } @@ -324,7 +324,7 @@ namespace Emby.Dlna } catch (Exception ex) { - _logger.LogError(ex, "Error parsing profile file: {0}", path); + _logger.LogError(ex, "Error parsing profile file: {Path}", path); return null; } diff --git a/Emby.Dlna/PlayTo/Device.cs b/Emby.Dlna/PlayTo/Device.cs index a1df90ec0..13bed6b2f 100644 --- a/Emby.Dlna/PlayTo/Device.cs +++ b/Emby.Dlna/PlayTo/Device.cs @@ -140,7 +140,7 @@ namespace Emby.Dlna.PlayTo } catch (Exception ex) { - _logger.LogError(ex, "Error updating device volume info for {0}", Properties.Name); + _logger.LogError(ex, "Error updating device volume info for {DeviceName}", Properties.Name); } } @@ -507,7 +507,7 @@ namespace Emby.Dlna.PlayTo if (_disposed) return; - //_logger.LogError(ex, "Error updating device info for {0}", Properties.Name); + _logger.LogError(ex, "Error updating device info for {DeviceName}", Properties.Name); _connectFailureCount++; diff --git a/Emby.Drawing.ImageMagick/ImageMagickEncoder.cs b/Emby.Drawing.ImageMagick/ImageMagickEncoder.cs index 6aac77cf4..5de8ac383 100644 --- a/Emby.Drawing.ImageMagick/ImageMagickEncoder.cs +++ b/Emby.Drawing.ImageMagick/ImageMagickEncoder.cs @@ -101,9 +101,9 @@ namespace Emby.Drawing.ImageMagick wand.SaveImage(tmpPath); } } - catch + catch (Exception ex) { - //_logger.LogError(ex, "Error loading webp: "); + _logger.LogError(ex, "Error loading webp"); _webpAvailable = false; } } diff --git a/Emby.Drawing/ImageProcessor.cs b/Emby.Drawing/ImageProcessor.cs index c417f3785..6a67be56d 100644 --- a/Emby.Drawing/ImageProcessor.cs +++ b/Emby.Drawing/ImageProcessor.cs @@ -646,16 +646,16 @@ namespace Emby.Drawing var cacheGuid = GetImageCacheTag(item, image, enhancers); // Enhance if we have enhancers - var ehnancedImageInfo = await GetEnhancedImageInternal(originalImagePath, item, imageType, imageIndex, enhancers, cacheGuid, cancellationToken).ConfigureAwait(false); + var enhancedImageInfo = await GetEnhancedImageInternal(originalImagePath, item, imageType, imageIndex, enhancers, cacheGuid, cancellationToken).ConfigureAwait(false); - var ehnancedImagePath = ehnancedImageInfo.Item1; + var enhancedImagePath = enhancedImageInfo.Item1; // If the path changed update dateModified - if (!string.Equals(ehnancedImagePath, originalImagePath, StringComparison.OrdinalIgnoreCase)) + if (!string.Equals(enhancedImagePath, originalImagePath, StringComparison.OrdinalIgnoreCase)) { - var treatmentRequiresTransparency = ehnancedImageInfo.Item2; + var treatmentRequiresTransparency = enhancedImageInfo.Item2; - return new ValueTuple(ehnancedImagePath, _fileSystem.GetLastWriteTimeUtc(ehnancedImagePath), treatmentRequiresTransparency); + return new ValueTuple(enhancedImagePath, _fileSystem.GetLastWriteTimeUtc(enhancedImagePath), treatmentRequiresTransparency); } } catch (Exception ex) diff --git a/Emby.IsoMounting/IsoMounter/LinuxIsoManager.cs b/Emby.IsoMounting/IsoMounter/LinuxIsoManager.cs index e6986ddcb..faaed482a 100644 --- a/Emby.IsoMounting/IsoMounter/LinuxIsoManager.cs +++ b/Emby.IsoMounting/IsoMounter/LinuxIsoManager.cs @@ -260,35 +260,29 @@ namespace IsoMounter } ); - try { - + try + { process.Start(); //StreamReader outputReader = process.StandardOutput.; //StreamReader errorReader = process.StandardError; _logger.LogDebug( - "[{0}] Standard output from process is [{1}].", + "[{Name}] Standard output from process is [{Error}].", Name, process.StandardOutput.ReadToEnd() ); _logger.LogDebug( - "[{0}] Standard error from process is [{1}].", + "[{Name}] Standard error from process is [{Error}].", Name, process.StandardError.ReadToEnd() ); - - } catch (Exception ex) { - + } + catch (Exception ex) + { processFailed = true; - - _logger.LogDebug( - "[{0}] Unhandled exception executing command, exception is [{1}].", - Name, - ex.Message - ); - + _logger.LogDebug(ex, "[{Name}] Unhandled exception executing command.", Name); } if (!processFailed && process.ExitCode == 0) { @@ -309,13 +303,13 @@ namespace IsoMounter if (!string.IsNullOrEmpty(isoPath)) { _logger.LogInformation( - "[{0}] Attempting to mount [{1}].", + "[{Name}] Attempting to mount [{Path}].", Name, isoPath ); _logger.LogDebug( - "[{0}] ISO will be mounted at [{1}].", + "[{Name}] ISO will be mounted at [{Path}].", Name, mountPoint ); @@ -326,11 +320,16 @@ namespace IsoMounter } - try { + try + { FileSystem.CreateDirectory(mountPoint); - } catch (UnauthorizedAccessException) { + } + catch (UnauthorizedAccessException) + { throw new IOException("Unable to create mount point(Permission denied) for " + isoPath); - } catch (Exception) { + } + catch (Exception) + { throw new IOException("Unable to create mount point for " + isoPath); } @@ -365,18 +364,13 @@ namespace IsoMounter Name ); - try { - + try + { FileSystem.DeleteDirectory(mountPoint, false); - - } catch (Exception ex) { - - _logger.LogInformation( - "[{0}] Unhandled exception removing mount point, exception is [{1}].", - Name, - ex.Message - ); - + } + catch (Exception ex) + { + _logger.LogInformation(ex, "[{Name}] Unhandled exception removing mount point.", Name); } mountedISO = null; @@ -439,20 +433,14 @@ namespace IsoMounter } - try { - + try + { FileSystem.DeleteDirectory(mount.MountedPath, false); - - } catch (Exception ex) { - - _logger.LogInformation( - "[{0}] Unhandled exception removing mount point, exception is [{1}].", - Name, - ex.Message - ); - } - + catch (Exception ex) + { + _logger.LogInformation(ex, "[{Name}] Unhandled exception removing mount point.", Name); + } } #endregion diff --git a/Emby.Server.Implementations/ApplicationHost.cs b/Emby.Server.Implementations/ApplicationHost.cs index 888635c9d..d4b740d71 100644 --- a/Emby.Server.Implementations/ApplicationHost.cs +++ b/Emby.Server.Implementations/ApplicationHost.cs @@ -2214,7 +2214,7 @@ namespace Emby.Server.Implementations } catch (Exception ex) { - Logger.LogDebug("Ping test result to {0}. Success: {1} {2}", apiUrl, false, ex.Message); + Logger.LogDebug(ex, "Ping test result to {0}. Success: {1}", apiUrl, false); _validAddressResults.AddOrUpdate(apiUrl, false, (k, v) => false); return false; diff --git a/Emby.Server.Implementations/Dto/DtoService.cs b/Emby.Server.Implementations/Dto/DtoService.cs index e8d06ec00..7871d3fb3 100644 --- a/Emby.Server.Implementations/Dto/DtoService.cs +++ b/Emby.Server.Implementations/Dto/DtoService.cs @@ -619,7 +619,7 @@ namespace Emby.Server.Implementations.Dto } catch (Exception ex) { - _logger.LogError(ex, "Error getting person {0}", c); + _logger.LogError(ex, "Error getting person {Name}", c); return null; } diff --git a/Emby.Server.Implementations/EntryPoints/ExternalPortForwarding.cs b/Emby.Server.Implementations/EntryPoints/ExternalPortForwarding.cs index a95e21e1c..6cd867921 100644 --- a/Emby.Server.Implementations/EntryPoints/ExternalPortForwarding.cs +++ b/Emby.Server.Implementations/EntryPoints/ExternalPortForwarding.cs @@ -166,6 +166,7 @@ namespace Emby.Server.Implementations.EntryPoints } catch (Exception ex) { + _logger.LogError(ex, "Error"); return; } diff --git a/Emby.Server.Implementations/IO/SharpCifs/Config.cs b/Emby.Server.Implementations/IO/SharpCifs/Config.cs index 3fd0e5bd6..324a9c494 100644 --- a/Emby.Server.Implementations/IO/SharpCifs/Config.cs +++ b/Emby.Server.Implementations/IO/SharpCifs/Config.cs @@ -89,7 +89,7 @@ namespace SharpCifs { Runtime.GetBytesForString(string.Empty, DefaultOemEncoding); } - catch (Exception ex) + catch (Exception) { if (_log.Level >= 2) { diff --git a/Emby.Server.Implementations/IO/SharpCifs/Dcerpc/DcerpcHandle.cs b/Emby.Server.Implementations/IO/SharpCifs/Dcerpc/DcerpcHandle.cs index 786b0ac12..e82af2b0c 100644 --- a/Emby.Server.Implementations/IO/SharpCifs/Dcerpc/DcerpcHandle.cs +++ b/Emby.Server.Implementations/IO/SharpCifs/Dcerpc/DcerpcHandle.cs @@ -153,7 +153,7 @@ namespace SharpCifs.Dcerpc DcerpcMessage bind = new DcerpcBind(Binding, this); Sendrecv(bind); } - catch (IOException ioe) + catch (IOException) { State = 0; throw; diff --git a/Emby.Server.Implementations/IO/SharpCifs/Netbios/Name.cs b/Emby.Server.Implementations/IO/SharpCifs/Netbios/Name.cs index 6c37d57a4..15ae494be 100644 --- a/Emby.Server.Implementations/IO/SharpCifs/Netbios/Name.cs +++ b/Emby.Server.Implementations/IO/SharpCifs/Netbios/Name.cs @@ -130,7 +130,7 @@ namespace SharpCifs.Netbios { name = Runtime.GetStringForBytes(tmp, 0, length).Trim(); } - catch (Exception ex) + catch (Exception) { } diff --git a/Emby.Server.Implementations/IO/SharpCifs/Netbios/NameServiceClient.cs b/Emby.Server.Implementations/IO/SharpCifs/Netbios/NameServiceClient.cs index 01700e64a..0d7840a64 100644 --- a/Emby.Server.Implementations/IO/SharpCifs/Netbios/NameServiceClient.cs +++ b/Emby.Server.Implementations/IO/SharpCifs/Netbios/NameServiceClient.cs @@ -117,8 +117,9 @@ namespace SharpCifs.Netbios { Baddr = Config.GetInetAddress("jcifs.netbios.baddr", Extensions.GetAddressByName("255.255.255.255")); } - catch (Exception ex) + catch (Exception) { + } _sndBuf = new byte[SndBufSize]; @@ -302,7 +303,10 @@ namespace SharpCifs.Netbios } } - catch (TimeoutException) { } + catch (TimeoutException) + { + + } catch (Exception ex) { if (_log.Level > 2) diff --git a/Emby.Server.Implementations/IO/SharpCifs/Smb/NtlmContext.cs b/Emby.Server.Implementations/IO/SharpCifs/Smb/NtlmContext.cs index 44266f974..aa52ee1db 100644 --- a/Emby.Server.Implementations/IO/SharpCifs/Smb/NtlmContext.cs +++ b/Emby.Server.Implementations/IO/SharpCifs/Smb/NtlmContext.cs @@ -192,7 +192,7 @@ namespace SharpCifs.Smb catch (Exception e) { throw new SmbException(e.Message, e); - } + } } default: