Skip to content

Commit 1246f9d

Browse files
committed
Fix the last Write-Error in Metadata
1 parent 991b463 commit 1246f9d

File tree

2 files changed

+19
-9
lines changed

2 files changed

+19
-9
lines changed

Source/Metadata.psm1

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,10 @@ function Add-MetadataConverter {
9292
if($Converters.Count) {
9393
switch ($Converters.Keys.GetEnumerator()) {
9494
{$Converters[$_] -isnot [ScriptBlock]} {
95-
Write-Error "Ignoring $_ converter, the value must be ScriptBlock!"
95+
WriteError -ExceptionType System.ArgumentExceptionn `
96+
-Message "Ignoring $_ converter, the value must be ScriptBlock!" `
97+
-ErrorId "NotAScriptBlock,Metadata\Add-MetadataConverter" `
98+
-Category "InvalidArgument"
9699
continue
97100
}
98101

@@ -112,7 +115,10 @@ function Add-MetadataConverter {
112115
continue
113116
}
114117
default {
115-
Write-Error "Unsupported key type in Converters: $_ is $($_.GetType())"
118+
WriteError -ExceptionType System.ArgumentExceptionn `
119+
-Message "Unsupported key type in Converters: $_ is $($_.GetType())" `
120+
-ErrorId "InvalidKeyType,Metadata\Add-MetadataConverter" `
121+
-Category "InvalidArgument"
116122
}
117123
}
118124
}

Specs/Configuration.Steps.ps1

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ AfterEachFeature {
1111

1212
Given 'the configuration module is imported with testing paths:' {
1313
param($Table)
14-
$ModuleBase = (Get-Module Configuration -ListAvailable | Sort Version -Descending)[0].ModuleBase
14+
$ModuleBase = (Get-Module Configuration -ListAvailable | Sort-Object Version -Descending)[0].ModuleBase
1515
Remove-Module Configuration -ErrorAction Ignore -Force
1616
Import-Module $ModuleBase\Configuration.psd1 -Args @($null, $Table.Enterprise, $Table.User, $Table.Machine) -Scope Global
1717
}
@@ -343,14 +343,15 @@ Given "the settings file does not exist" {
343343

344344

345345
# This step will create verifiable/counting loggable mocks for Write-Warning, Write-Error, Write-Verbose
346-
When "we expect an? (?<type>warning|error|verbose) in the (?<module>.*) module" {
346+
Given "we expect an? (?<type>warning|error|verbose) in the (?<module>.*) module" {
347347
param($type, $module)
348348
$ErrorModule = $module
349349

350-
Mock -Module $ErrorModule Write-$type { $true } -Verifiable
351350
# The Metadata module hides itself a little bit
352351
if($Type -eq "Error" -and ($ErrorModule -eq "Metadata")) {
353-
Mock -Module $ErrorModule WriteError { Write-Error "Error" -TargetObject $Args }
352+
Mock -Module $ErrorModule WriteError { Write-Host " WriteError: $Message" -Foreground Red } -Verifiable
353+
} else {
354+
Mock -Module $ErrorModule Write-$type { Write-Host " Write-Error: $Message" -Foreground Red } -Verifiable
354355
}
355356
}
356357

@@ -366,7 +367,11 @@ When "the (?<type>warning|error|verbose) is logged(?: (?<exactly>exactly) (\d+)
366367
$param.Times = $count
367368
}
368369

369-
Assert-MockCalled -Module $ErrorModule -Command Write-$type @param
370+
if($Type -eq "Error" -and ($ErrorModule -eq "Metadata")) {
371+
Assert-MockCalled -Module $ErrorModule -Command WriteError @param
372+
} else {
373+
Assert-MockCalled -Module $ErrorModule -Command Write-$type @param
374+
}
370375
}
371376

372377
When "we add a converter that's not a scriptblock" {
@@ -401,8 +406,7 @@ Then "the settings object should have an? (.*) of type (.*)" {
401406
Then "the settings object's (.*) should (be of type|be) (.*)" {
402407
param([String]$Parameter, [String]$operator, $Expected)
403408
$Value = $Settings
404-
405-
# # Write-Debug ($Settings | Out-String)
409+
Set-StrictMode -Off
406410

407411
foreach($property in $Parameter.Split(".")) {
408412
$value = $value.$property

0 commit comments

Comments
 (0)