From d0406ced40dec4a9f3b5148f543cdf1462b67be0 Mon Sep 17 00:00:00 2001 From: Qstick Date: Mon, 19 Feb 2018 08:19:14 +0100 Subject: [PATCH] Fixed: Unable to execute custom scripts if IMDB ID is null (#2543) fixes #1460 --- .../Processes/ProcessProvider.cs | 36 ++++++++++++++----- .../CustomScript/CustomScript.cs | 6 ++-- 2 files changed, 30 insertions(+), 12 deletions(-) diff --git a/src/NzbDrone.Common/Processes/ProcessProvider.cs b/src/NzbDrone.Common/Processes/ProcessProvider.cs index c3e3dcb64..a6a837f8c 100644 --- a/src/NzbDrone.Common/Processes/ProcessProvider.cs +++ b/src/NzbDrone.Common/Processes/ProcessProvider.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections; using System.Collections.Generic; using System.Collections.Specialized; @@ -98,9 +98,9 @@ public void OpenDefaultBrowser(string url) var process = new Process { StartInfo = new ProcessStartInfo(url) - { - UseShellExecute = true - } + { + UseShellExecute = true + } }; process.Start(); @@ -129,16 +129,34 @@ public Process Start(string path, string args = null, StringDictionary environme { foreach (DictionaryEntry environmentVariable in environmentVariables) { - startInfo.EnvironmentVariables.Add(environmentVariable.Key.ToString(), environmentVariable.Value.ToString()); + try + { + _logger.Trace("Setting environment variable '{0}' to '{1}'", environmentVariable.Key, environmentVariable.Value); + startInfo.EnvironmentVariables.Add(environmentVariable.Key.ToString(), environmentVariable.Value.ToString()); + } + catch (Exception e) + { + if (environmentVariable.Value == null) + { + _logger.Error(e, "Unable to set environment variable '{0}', value is null", environmentVariable.Key); + } + + else + { + _logger.Error(e, "Unable to set environment variable '{0}'", environmentVariable.Key); + } + + throw; + } } } logger.Debug("Starting {0} {1}", path, args); var process = new Process - { - StartInfo = startInfo - }; + { + StartInfo = startInfo + }; process.OutputDataReceived += (sender, eventArgs) => { @@ -315,7 +333,7 @@ private List GetProcessesByName(string name) var monoProcesses = Process.GetProcessesByName("mono") .Union(Process.GetProcessesByName("mono-sgen")) - .Union(Process.GetProcessesByName("mono-sgen32")) + .Union(Process.GetProcessesByName("mono-sgen32")) .Where(process => process.Modules.Cast() .Any(module => diff --git a/src/NzbDrone.Core/Notifications/CustomScript/CustomScript.cs b/src/NzbDrone.Core/Notifications/CustomScript/CustomScript.cs index 3d39c56e1..314a83ce3 100755 --- a/src/NzbDrone.Core/Notifications/CustomScript/CustomScript.cs +++ b/src/NzbDrone.Core/Notifications/CustomScript/CustomScript.cs @@ -37,7 +37,7 @@ public override void OnGrab(GrabMessage message) environmentVariables.Add("Radarr_EventType", "Grab"); environmentVariables.Add("Radarr_Movie_Id", movie.Id.ToString()); environmentVariables.Add("Radarr_Movie_Title", movie.Title); - environmentVariables.Add("Radarr_Movie_ImdbId", movie.ImdbId); + environmentVariables.Add("Radarr_Movie_ImdbId", movie.ImdbId ?? string.Empty); environmentVariables.Add("Radarr_Movie_TmdbId", movie.TmdbId.ToString()); environmentVariables.Add("Radarr_Release_Title", remoteMovie.Release.Title); environmentVariables.Add("Radarr_Release_Indexer", remoteMovie.Release.Indexer); @@ -61,7 +61,7 @@ public override void OnDownload(DownloadMessage message) environmentVariables.Add("Radarr_Movie_Id", movie.Id.ToString()); environmentVariables.Add("Radarr_Movie_Title", movie.Title); environmentVariables.Add("Radarr_Movie_Path", movie.Path); - environmentVariables.Add("Radarr_Movie_ImdbId", movie.ImdbId); + environmentVariables.Add("Radarr_Movie_ImdbId", movie.ImdbId ?? string.Empty); environmentVariables.Add("Radarr_Movie_TmdbId", movie.TmdbId.ToString()); environmentVariables.Add("Radarr_MovieFile_Id", movieFile.Id.ToString()); environmentVariables.Add("Radarr_MovieFile_RelativePath", movieFile.RelativePath); @@ -90,7 +90,7 @@ public override void OnMovieRename(Movie movie) environmentVariables.Add("Radarr_Movie_Id", movie.Id.ToString()); environmentVariables.Add("Radarr_Movie_Title", movie.Title); environmentVariables.Add("Radarr_Movie_Path", movie.Path); - environmentVariables.Add("Radarr_Movie_ImdbId", movie.ImdbId); + environmentVariables.Add("Radarr_Movie_ImdbId", movie.ImdbId ?? string.Empty); environmentVariables.Add("Radarr_Movie_TmdbId", movie.TmdbId.ToString()); ExecuteScript(environmentVariables);