Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix how PSAdapter writes traces #528

Merged
merged 1 commit into from
Aug 26, 2024
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
9 changes: 4 additions & 5 deletions powershell-adapter/psDscAdapter/psDscAdapter.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ function Get-DscResourceObject {

# catch potential for improperly formatted configuration input
if ($inputObj.resources -and -not $inputObj.metadata.'Microsoft.DSC'.context -eq 'configuration') {
'WARNING: The input has a top level property named "resources" but is not a configuration. If the input should be a configuration, include the property: "metadata": {"Microsoft.DSC": {"context": "Configuration"}}' | Write-DscTrace
'The input has a top level property named "resources" but is not a configuration. If the input should be a configuration, include the property: "metadata": {"Microsoft.DSC": {"context": "Configuration"}}' | Write-DscTrace -Operation Warn
}

$adapterName = 'Microsoft.DSC/PowerShell'
Expand Down Expand Up @@ -486,12 +486,12 @@ function Invoke-DscOperation {
}
catch {

'ERROR: ' + $_.Exception.Message | Write-DscTrace
'Exception: ' + $_.Exception.Message | Write-DscTrace -Operation Error
exit 1
}
}
Default {
'Resource ImplementationDetail not supported: ' + $cachedDscResourceInfo.ImplementationDetail | Write-DscTrace
'Resource ImplementationDetail not supported: ' + $cachedDscResourceInfo.ImplementationDetail | Write-DscTrace -Operation Error
exit 1
}
}
Expand All @@ -500,8 +500,7 @@ function Invoke-DscOperation {
}
else {
$dsJSON = $DesiredState | ConvertTo-Json -Depth 10
$errmsg = 'Can not find type "' + $DesiredState.type + '" for resource "' + $dsJSON + '". Please ensure that Get-DscResource returns this resource type.'
'ERROR: ' + $errmsg | Write-DscTrace
'Can not find type "' + $DesiredState.type + '" for resource "' + $dsJSON + '". Please ensure that Get-DscResource returns this resource type.' | Write-DscTrace -Operation Error
exit 1
}
}
Expand Down
17 changes: 8 additions & 9 deletions powershell-adapter/psDscAdapter/win_psDscAdapter.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ else {
$env:PSModulePath += ";$env:windir\System32\WindowsPowerShell\v1.0\Modules"
$PSDesiredStateConfiguration = Import-Module -Name 'PSDesiredStateConfiguration' -RequiredVersion '1.1' -Force -PassThru -ErrorAction stop -ErrorVariable $importModuleError
if (-not [string]::IsNullOrEmpty($importModuleError)) {
'ERROR: Could not import PSDesiredStateConfiguration 1.1 in Windows PowerShell. ' + $importModuleError | Write-DscTrace
'Could not import PSDesiredStateConfiguration 1.1 in Windows PowerShell. ' + $importModuleError | Write-DscTrace -Operation Error
}
}

Expand Down Expand Up @@ -173,7 +173,7 @@ function Invoke-DscCacheRefresh {
if ( $psdscVersion -ge '2.0.7' ) {
# only support known dscResourceType
if ([dscResourceType].GetEnumNames() -notcontains $dscResource.ImplementationDetail) {
'WARNING: implementation detail not found: ' + $dscResource.ImplementationDetail | Write-DscTrace
'Implementation detail not found: ' + $dscResource.ImplementationDetail | Write-DscTrace -Operation Warn
continue
}
}
Expand Down Expand Up @@ -261,7 +261,7 @@ function Get-DscResourceObject {

# catch potential for improperly formatted configuration input
if ($inputObj.resources -and -not $inputObj.metadata.'Microsoft.DSC'.context -eq 'configuration') {
'WARNING: The input has a top level property named "resources" but is not a configuration. If the input should be a configuration, include the property: "metadata": {"Microsoft.DSC": {"context": "Configuration"}}' | Write-DscTrace
'The input has a top level property named "resources" but is not a configuration. If the input should be a configuration, include the property: "metadata": {"Microsoft.DSC": {"context": "Configuration"}}' | Write-DscTrace -Operation Warn
}

# match adapter to version of powershell
Expand Down Expand Up @@ -338,7 +338,7 @@ function Invoke-DscOperation {

# For Linux/MacOS, only class based resources are supported and are called directly.
if ($IsLinux) {
'ERROR: Script based resources are only supported on Windows.' | Write-DscTrace
'Script based resources are only supported on Windows.' | Write-DscTrace -Operation Error
exit 1
}

Expand Down Expand Up @@ -374,7 +374,7 @@ function Invoke-DscOperation {
$addToActualState.properties = $ResultProperties
}
catch {
'ERROR: ' + $_.Exception.Message | Write-DscTrace
'Exception: ' + $_.Exception.Message | Write-DscTrace -Operation Error
exit 1
}
}
Expand Down Expand Up @@ -413,7 +413,7 @@ function Invoke-DscOperation {
}
catch {

'ERROR: ' + $_.Exception.Message | Write-DscTrace
'Exception: ' + $_.Exception.Message | Write-DscTrace -Operation Error
exit 1
}
}
Expand Down Expand Up @@ -445,7 +445,7 @@ function Invoke-DscOperation {
$addToActualState.properties = $ResultProperties
}
catch {
'ERROR: ' + $_.Exception.Message | Write-DscTrace
'Exception: ' + $_.Exception.Message | Write-DscTrace -Operation Error
exit 1
}
}
Expand All @@ -459,8 +459,7 @@ function Invoke-DscOperation {
}
else {
$dsJSON = $DesiredState | ConvertTo-Json -Depth 10
$errmsg = 'Can not find type "' + $DesiredState.type + '" for resource "' + $dsJSON + '". Please ensure that Get-DscResource returns this resource type.'
'ERROR: ' + $errmsg | Write-DscTrace
'Can not find type "' + $DesiredState.type + '" for resource "' + $dsJSON + '". Please ensure that Get-DscResource returns this resource type.' | Write-DscTrace -Operation Error
exit 1
}
}
Expand Down
Loading