From a581a046064ba915cfb33911e3893aaed3419086 Mon Sep 17 00:00:00 2001 From: jvlflame Date: Wed, 2 Sep 2020 20:53:52 -0700 Subject: [PATCH] Add trycatch for -Set --- src/Javinizer/Public/Javinizer.ps1 | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/Javinizer/Public/Javinizer.ps1 b/src/Javinizer/Public/Javinizer.ps1 index a050f6e6..e0c9b54a 100644 --- a/src/Javinizer/Public/Javinizer.ps1 +++ b/src/Javinizer/Public/Javinizer.ps1 @@ -210,11 +210,15 @@ function Javinizer { } if ($Set) { - foreach ($item in $Set.GetEnumerator()) { - $settingName = $item.Key - $settingValue = $item.Value - $Settings."$($item.Key)" = $item.Value - Write-JVLog -Write:$script:JVLogWrite -LogPath $script:JVLogPath -WriteLevel $script:JVLogWriteLevel -Level Debug -Message "[$($MyInvocation.MyCommand.Name)] [Setting - $($item.Key)] replaced as [$($item.Value)]" + try { + foreach ($item in $Set.GetEnumerator()) { + $settingName = $item.Key + $settingValue = $item.Value + $Settings."$($item.Key)" = $item.Value + Write-JVLog -Write:$script:JVLogWrite -LogPath $script:JVLogPath -WriteLevel $script:JVLogWriteLevel -Level Debug -Message "[$($MyInvocation.MyCommand.Name)] [Setting - $($item.Key)] replaced as [$($item.Value)]" + } + } catch { + Write-JVLog -Write:$script:JVLogWrite -LogPath $script:JVLogPath -WriteLevel $script:JVLogWriteLevel -Level Error -Message "[$($MyInvocation.MyCommand.Name)] Error occurred when defining settings using -Set: $PSItem" } } @@ -379,13 +383,13 @@ function Javinizer { } } } else { - if ($Settings.'scraper.throttlelimit' -lt 1 -or $Settings.'scraper.throttlelimit' -gt 5) { - Write-JVLog -Write $script:JVLogWrite -LogPath $script:JVLogPath -WriteLevel $script:JVLogWriteLevel -Level Error -Message "[$($MyInvocation.MyCommand.Name)] Error occured while starting multi sort: Setting 'scraper.throttlelimit' must be within accepted values (1-5)" + if ($Settings.'throttlelimit' -lt 1 -or $Settings.'throttlelimit' -gt 5) { + Write-JVLog -Write $script:JVLogWrite -LogPath $script:JVLogPath -WriteLevel $script:JVLogWriteLevel -Level Error -Message "[$($MyInvocation.MyCommand.Name)] Setting 'scraper.throttlelimit' must be within accepted values (1-5)" } if ($PSBoundParameters.ContainsKey('Multi')) { $jvModulePath = Join-Path -Path ((Get-Item $PSScriptRoot).Parent) -ChildPath 'Javinizer.psm1' try { - $javMovies | Invoke-Parallel -MaxQueue $Settings.'scraper.throttlelimit' -Throttle $Settings.'scraper.throttlelimit' -Quiet:$HideProgress -ScriptBlock { + $javMovies | Invoke-Parallel -MaxQueue $Settings.'throttlelimit' -Throttle $Settings.'throttlelimit' -Quiet:$HideProgress -ScriptBlock { Import-Module $using:jvModulePath $jvMovie = $_ Javinizer -Path $jvMovie.FullName -DestinationPath $using:DestinationPath -Set $using:Set -SettingsPath:$using:SettingsPath -Strict:$using:Strict -Force:$using:Force -Verbose:$using:VerbosePreference -Debug:$using:DebugPreference