Skip to content

Commit

Permalink
Merge pull request #570 from PlagueHO/Issue-409
Browse files Browse the repository at this point in the history
xRemoteFile: Updated documentation for MatchSource - Fixes #409
  • Loading branch information
mhendric authored Feb 23, 2019
2 parents 60eb4aa + 057d622 commit bef6bd1
Show file tree
Hide file tree
Showing 6 changed files with 290 additions and 72 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,17 @@

## Unreleased

- xRemoteFile
- Updated MatchSource description in README.md.
[issue #409](https://github.com/PowerShell/xPSDesiredStateConfiguration/issues/409)
- Improved layout of MOF file to move description left.
- Added function help for all functions.
- Moved `New-InvalidDataException` to CommonResourceHelper.psm1.
[issue #544](https://github.com/PowerShell/xPSDesiredStateConfiguration/issues/544)
- Added full stops to the end of all functions help in CommonResourceHelper.psm1.
- Added unit tests for `New-InvalidArgumentException`, `New-InvalidDataException` and
`New-InvalidOperationException` CommonResourceHelper.psm1 functions.

## 8.5.0.0

- Pull server module publishing
Expand Down
80 changes: 58 additions & 22 deletions DSCResources/CommonResourceHelper.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,13 @@ function Test-CommandExists

<#
.SYNOPSIS
Creates and throws an invalid argument exception
Creates and throws an invalid argument exception.
.PARAMETER Message
The message explaining why this error is being thrown
The message explaining why this error is being thrown.
.PARAMETER ArgumentName
The name of the invalid argument that is causing this error to be thrown
The name of the invalid argument that is causing this error to be thrown.
#>
function New-InvalidArgumentException
{
Expand All @@ -75,9 +75,9 @@ function New-InvalidArgumentException
)

$argumentException = New-Object -TypeName 'ArgumentException' `
-ArgumentList @($Message, $ArgumentName)
-ArgumentList @($Message, $ArgumentName)
$newObjectParams = @{
TypeName = 'System.Management.Automation.ErrorRecord'
TypeName = 'System.Management.Automation.ErrorRecord'
ArgumentList = @($argumentException, $ArgumentName, 'InvalidArgument', $null)
}
$errorRecord = New-Object @newObjectParams
Expand All @@ -87,13 +87,49 @@ function New-InvalidArgumentException

<#
.SYNOPSIS
Creates and throws an invalid operation exception
Creates and throws an invalid data exception.
.PARAMETER ErrorId
The error Id to assign to the exception.
.PARAMETER ErrorMessage
The error message to assign to the exception.
#>
function New-InvalidDataException
{
[CmdletBinding()]
param
(
[Parameter(Mandatory = $true)]
[System.String]
$ErrorId,

[Parameter(Mandatory = $true)]
[System.String]
$ErrorMessage
)

$errorCategory = [System.Management.Automation.ErrorCategory]::InvalidData
$exception = New-Object `
-TypeName System.InvalidOperationException `
-ArgumentList $ErrorMessage
$errorRecord = New-Object `
-TypeName System.Management.Automation.ErrorRecord `
-ArgumentList $exception, $ErrorId, $errorCategory, $null

throw $errorRecord
}

<#
.SYNOPSIS
Creates and throws an invalid operation exception.
.PARAMETER Message
The message explaining why this error is being thrown
The message explaining why this error is being thrown.
.PARAMETER ErrorRecord
The error record containing the exception that is causing this terminating error
The error record containing the exception that is causing this terminating
error.
#>
function New-InvalidOperationException
{
Expand All @@ -118,18 +154,17 @@ function New-InvalidOperationException
elseif ($null -eq $ErrorRecord)
{
$invalidOperationException = New-Object -TypeName 'InvalidOperationException' `
-ArgumentList @($Message)
-ArgumentList @( $Message )
}
else
{
$invalidOperationException = New-Object -TypeName 'InvalidOperationException' `
-ArgumentList @($Message, $ErrorRecord.Exception)
-ArgumentList @( $Message, $ErrorRecord.Exception )
}

$newObjectParams = @{
TypeName = 'System.Management.Automation.ErrorRecord'
ArgumentList = @( $invalidOperationException.ToString(), 'MachineStateIncorrect',
'InvalidOperation', $null )
TypeName = 'System.Management.Automation.ErrorRecord'
ArgumentList = @( $invalidOperationException.ToString(), 'MachineStateIncorrect', 'InvalidOperation', $null )
}

$errorRecordToThrow = New-Object @newObjectParams
Expand All @@ -142,7 +177,8 @@ function New-InvalidOperationException
Falls back to en-US strings if the machine's culture is not supported.
.PARAMETER ResourceName
The name of the resource as it appears before '.strings.psd1' of the localized string file.
The name of the resource as it appears before '.strings.psd1' of the localized
string file.
For example:
For xWindowsOptionalFeature: MSFT_xWindowsOptionalFeature
For xService: MSFT_xServiceResource
Expand Down Expand Up @@ -197,11 +233,11 @@ function Set-DSCMachineRebootRequired
$global:DSCMachineStatus = 1
}

Export-ModuleMember `
-Function @(
'Test-IsNanoServer',
'New-InvalidArgumentException',
'New-InvalidOperationException',
'Get-LocalizedData',
'Set-DSCMachineRebootRequired'
)
Export-ModuleMember -Function @(
'Test-IsNanoServer',
'New-InvalidArgumentException',
'New-InvalidDataException',
'New-InvalidOperationException',
'Get-LocalizedData',
'Set-DSCMachineRebootRequired'
)
Loading

0 comments on commit bef6bd1

Please sign in to comment.