Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Fixed Azure DevOps pipeline conditions that were preventing DSC resource
integration tests from running when they should by removing incorrect quotes
around boolean values.
- Refactored error handling by removing global `$ErrorActionPreference = 'Stop'`
from 64 PowerShell files and implementing targeted error control for specific
command calls that use `-ErrorAction 'Stop'`.
- `SqlAgentAlert`
- Minor fix in `source/Classes/020.SqlAgentAlert.ps1` to correct `ExcludeDscProperties`
formatting (added missing delimiter).
Expand Down
6 changes: 6 additions & 0 deletions source/Private/Get-FileVersionInformation.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,14 @@ function Get-FileVersionInformation

process
{
$originalErrorActionPreference = $ErrorActionPreference

$ErrorActionPreference = 'Stop'

$file = Get-Item -Path $FilePath -ErrorAction 'Stop'

$ErrorActionPreference = $originalErrorActionPreference

if ($file.PSIsContainer)
{
$PSCmdlet.ThrowTerminatingError(
Expand Down
6 changes: 6 additions & 0 deletions source/Private/Invoke-ReportServerSetupAction.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,14 @@ function Invoke-ReportServerSetupAction
$ConfirmPreference = 'None'
}

$originalErrorActionPreference = $ErrorActionPreference

$ErrorActionPreference = 'Stop'

Assert-ElevatedUser -ErrorAction 'Stop'

$ErrorActionPreference = $originalErrorActionPreference

$assertBoundParameters = @{
BoundParameterList = $PSBoundParameters
MutuallyExclusiveList1 = @(
Expand Down
4 changes: 2 additions & 2 deletions source/Private/Invoke-SetupAction.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -1372,7 +1372,7 @@ function Invoke-SetupAction
$Force
)

$previousErrorActionPreference = $ErrorActionPreference
$originalErrorActionPreference = $ErrorActionPreference

$ErrorActionPreference = 'Stop'

Expand Down Expand Up @@ -1415,7 +1415,7 @@ function Invoke-SetupAction

Assert-SetupActionProperties -Property $PSBoundParameters -SetupAction $setupAction -ErrorAction 'Stop'

$ErrorActionPreference = $previousErrorActionPreference
$ErrorActionPreference = $originalErrorActionPreference

$setupArgument = '/QUIET /ACTION={0}' -f $setupAction

Expand Down
12 changes: 12 additions & 0 deletions source/Public/Add-SqlDscTraceFlag.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,14 @@ function Add-SqlDscTraceFlag
$getSqlDscTraceFlagParameters.Remove($_)
}

$originalErrorActionPreference = $ErrorActionPreference

$ErrorActionPreference = 'Stop'

$currentTraceFlags = Get-SqlDscTraceFlag @getSqlDscTraceFlagParameters -ErrorAction 'Stop'

$ErrorActionPreference = $originalErrorActionPreference

$desiredTraceFlags = [System.UInt32[]] $currentTraceFlags + @(
$TraceFlag |
ForEach-Object -Process {
Expand All @@ -130,7 +136,13 @@ function Add-SqlDscTraceFlag

$setSqlDscTraceFlagParameters.TraceFLag = $desiredTraceFlags

$originalErrorActionPreference = $ErrorActionPreference

$ErrorActionPreference = 'Stop'

Set-SqlDscTraceFlag @setSqlDscTraceFlagParameters -ErrorAction 'Stop'

$ErrorActionPreference = $originalErrorActionPreference
}
}
}
6 changes: 3 additions & 3 deletions source/Public/Get-SqlDscStartupParameter.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -65,19 +65,19 @@ function Get-SqlDscStartupParameter
$InstanceName = 'MSSQLSERVER'
)

$previousErrorActionPreference = $ErrorActionPreference
$originalErrorActionPreference = $ErrorActionPreference

$ErrorActionPreference = 'Stop'

Assert-ElevatedUser -ErrorAction 'Stop'

$ErrorActionPreference = $originalErrorActionPreference

if ($PSCmdlet.ParameterSetName -eq 'ByServiceObject')
{
$ServiceObject | Assert-ManagedServiceType -ServiceType 'DatabaseEngine'
}

$ErrorActionPreference = $previousErrorActionPreference

if ($PSCmdlet.ParameterSetName -eq 'ByServerName')
{
$getSqlDscManagedComputerServiceParameters = @{
Expand Down
14 changes: 14 additions & 0 deletions source/Public/Import-SqlDscPreferredModule.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ function Import-SqlDscPreferredModule

$availableModule = $null

$originalErrorActionPreference = $ErrorActionPreference

$ErrorActionPreference = 'Stop'

try
{
$availableModule = Get-SqlDscPreferredModule @getSqlDscPreferredModuleParameters -ErrorAction 'Stop'
Expand All @@ -87,6 +91,10 @@ function Import-SqlDscPreferredModule
)
)
}
finally
{
$ErrorActionPreference = $originalErrorActionPreference
}

if ($Force.IsPresent -and -not $Confirm)
{
Expand Down Expand Up @@ -133,12 +141,18 @@ function Import-SqlDscPreferredModule

Push-Location

$originalErrorActionPreference = $ErrorActionPreference

$ErrorActionPreference = 'Stop'

<#
SQLPS has unapproved verbs, disable checking to ignore Warnings.
Suppressing verbose so all cmdlet is not listed.
#>
$importedModule = Import-Module -ModuleInfo $availableModule -DisableNameChecking -Verbose:$false -Force:$Force -Global -PassThru -ErrorAction 'Stop'

$ErrorActionPreference = $originalErrorActionPreference

<#
SQLPS returns two entries, one with module type 'Script' and another with module type 'Manifest'.
Only return the object with module type 'Manifest'.
Expand Down
12 changes: 12 additions & 0 deletions source/Public/Remove-SqlDscTraceFlag.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,14 @@ function Remove-SqlDscTraceFlag
$getSqlDscTraceFlagParameters.Remove($_)
}

$originalErrorActionPreference = $ErrorActionPreference

$ErrorActionPreference = 'Stop'

$currentTraceFlags = Get-SqlDscTraceFlag @getSqlDscTraceFlagParameters -ErrorAction 'Stop'

$ErrorActionPreference = $originalErrorActionPreference

if ($currentTraceFlags)
{
# Must always return an array. An empty array when removing the last value.
Expand All @@ -133,7 +139,13 @@ function Remove-SqlDscTraceFlag

$setSqlDscTraceFlagParameters.TraceFLag = $desiredTraceFlags

$originalErrorActionPreference = $ErrorActionPreference

$ErrorActionPreference = 'Stop'

Set-SqlDscTraceFlag @setSqlDscTraceFlagParameters -ErrorAction 'Stop'

$ErrorActionPreference = $originalErrorActionPreference
}
}
else
Expand Down
8 changes: 4 additions & 4 deletions source/Public/Set-SqlDscStartupParameter.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -91,18 +91,18 @@ function Set-SqlDscStartupParameter

begin
{
$previousErrorActionPreference = $ErrorActionPreference
$originalErrorActionPreference = $ErrorActionPreference

$ErrorActionPreference = 'Stop'

Assert-ElevatedUser -ErrorAction 'Stop'

$ErrorActionPreference = $originalErrorActionPreference

if ($Force.IsPresent -and -not $Confirm)
{
$ConfirmPreference = 'None'
}

$ErrorActionPreference = $previousErrorActionPreference
}

process
Expand All @@ -120,7 +120,7 @@ function Set-SqlDscStartupParameter
ServerName = $ServerName
InstanceName = $InstanceName
ServiceType = 'DatabaseEngine'
ErrorAction = 'Stop'
ErrorAction = 'SilentlyContinue'
}

$ServiceObject = Get-SqlDscManagedComputerService @getSqlDscManagedComputerServiceParameters
Expand Down
Loading