Skip to content

Commit dc78c0c

Browse files
authored
Merge pull request #528 from SteveL-MSFT/psadapter-trace
Fix how PSAdapter writes traces
2 parents fa11827 + 84d1d81 commit dc78c0c

File tree

2 files changed

+12
-14
lines changed

2 files changed

+12
-14
lines changed

powershell-adapter/psDscAdapter/psDscAdapter.psm1

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,7 @@ function Get-DscResourceObject {
384384

385385
# catch potential for improperly formatted configuration input
386386
if ($inputObj.resources -and -not $inputObj.metadata.'Microsoft.DSC'.context -eq 'configuration') {
387-
'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
387+
'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
388388
}
389389

390390
$adapterName = 'Microsoft.DSC/PowerShell'
@@ -486,12 +486,12 @@ function Invoke-DscOperation {
486486
}
487487
catch {
488488

489-
'ERROR: ' + $_.Exception.Message | Write-DscTrace
489+
'Exception: ' + $_.Exception.Message | Write-DscTrace -Operation Error
490490
exit 1
491491
}
492492
}
493493
Default {
494-
'Resource ImplementationDetail not supported: ' + $cachedDscResourceInfo.ImplementationDetail | Write-DscTrace
494+
'Resource ImplementationDetail not supported: ' + $cachedDscResourceInfo.ImplementationDetail | Write-DscTrace -Operation Error
495495
exit 1
496496
}
497497
}
@@ -500,8 +500,7 @@ function Invoke-DscOperation {
500500
}
501501
else {
502502
$dsJSON = $DesiredState | ConvertTo-Json -Depth 10
503-
$errmsg = 'Can not find type "' + $DesiredState.type + '" for resource "' + $dsJSON + '". Please ensure that Get-DscResource returns this resource type.'
504-
'ERROR: ' + $errmsg | Write-DscTrace
503+
'Can not find type "' + $DesiredState.type + '" for resource "' + $dsJSON + '". Please ensure that Get-DscResource returns this resource type.' | Write-DscTrace -Operation Error
505504
exit 1
506505
}
507506
}

powershell-adapter/psDscAdapter/win_psDscAdapter.psm1

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ else {
2828
$env:PSModulePath += ";$env:windir\System32\WindowsPowerShell\v1.0\Modules"
2929
$PSDesiredStateConfiguration = Import-Module -Name 'PSDesiredStateConfiguration' -RequiredVersion '1.1' -Force -PassThru -ErrorAction stop -ErrorVariable $importModuleError
3030
if (-not [string]::IsNullOrEmpty($importModuleError)) {
31-
'ERROR: Could not import PSDesiredStateConfiguration 1.1 in Windows PowerShell. ' + $importModuleError | Write-DscTrace
31+
'Could not import PSDesiredStateConfiguration 1.1 in Windows PowerShell. ' + $importModuleError | Write-DscTrace -Operation Error
3232
}
3333
}
3434

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

262262
# catch potential for improperly formatted configuration input
263263
if ($inputObj.resources -and -not $inputObj.metadata.'Microsoft.DSC'.context -eq 'configuration') {
264-
'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
264+
'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
265265
}
266266

267267
# match adapter to version of powershell
@@ -338,7 +338,7 @@ function Invoke-DscOperation {
338338

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

@@ -374,7 +374,7 @@ function Invoke-DscOperation {
374374
$addToActualState.properties = $ResultProperties
375375
}
376376
catch {
377-
'ERROR: ' + $_.Exception.Message | Write-DscTrace
377+
'Exception: ' + $_.Exception.Message | Write-DscTrace -Operation Error
378378
exit 1
379379
}
380380
}
@@ -413,7 +413,7 @@ function Invoke-DscOperation {
413413
}
414414
catch {
415415

416-
'ERROR: ' + $_.Exception.Message | Write-DscTrace
416+
'Exception: ' + $_.Exception.Message | Write-DscTrace -Operation Error
417417
exit 1
418418
}
419419
}
@@ -445,7 +445,7 @@ function Invoke-DscOperation {
445445
$addToActualState.properties = $ResultProperties
446446
}
447447
catch {
448-
'ERROR: ' + $_.Exception.Message | Write-DscTrace
448+
'Exception: ' + $_.Exception.Message | Write-DscTrace -Operation Error
449449
exit 1
450450
}
451451
}
@@ -459,8 +459,7 @@ function Invoke-DscOperation {
459459
}
460460
else {
461461
$dsJSON = $DesiredState | ConvertTo-Json -Depth 10
462-
$errmsg = 'Can not find type "' + $DesiredState.type + '" for resource "' + $dsJSON + '". Please ensure that Get-DscResource returns this resource type.'
463-
'ERROR: ' + $errmsg | Write-DscTrace
462+
'Can not find type "' + $DesiredState.type + '" for resource "' + $dsJSON + '". Please ensure that Get-DscResource returns this resource type.' | Write-DscTrace -Operation Error
464463
exit 1
465464
}
466465
}

0 commit comments

Comments
 (0)