mirror of
https://github.com/Raphire/Win11Debloat.git
synced 2026-08-22 07:36:25 +00:00
Surface errors when writing to file
This commit is contained in:
@@ -27,10 +27,11 @@ function Save-ToFile {
|
|||||||
)
|
)
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$Config | ConvertTo-Json -Depth $MaxDepth | Set-Content -Path $FilePath -Encoding UTF8
|
$Config | ConvertTo-Json -Depth $MaxDepth | Set-Content -Path $FilePath -Encoding UTF8 -ErrorAction Stop
|
||||||
return $true
|
return $true
|
||||||
}
|
}
|
||||||
catch {
|
catch {
|
||||||
|
Write-Error "Failed to write '$FilePath': $($_.Exception.Message)"
|
||||||
return $false
|
return $false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,6 +14,19 @@ BeforeAll {
|
|||||||
$script:JsonFixturePath = Join-Path $PSScriptRoot 'TestData\JsonFileLoading'
|
$script:JsonFixturePath = Join-Path $PSScriptRoot 'TestData\JsonFileLoading'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Describe 'Save-ToFile' {
|
||||||
|
It 'reports the write error and returns false when persistence fails' {
|
||||||
|
Mock Set-Content { throw [System.IO.IOException]::new('Disk is full') }
|
||||||
|
Mock Write-Error {}
|
||||||
|
|
||||||
|
Save-ToFile -Config @{ Setting = $true } -FilePath (Join-Path $TestDrive 'settings.json') | Should -BeFalse
|
||||||
|
|
||||||
|
Should -Invoke Write-Error -Times 1 -Exactly -ParameterFilter {
|
||||||
|
$Message -eq "Failed to write '$TestDrive\settings.json': Disk is full"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Describe 'Import-Settings' {
|
Describe 'Import-Settings' {
|
||||||
BeforeEach {
|
BeforeEach {
|
||||||
$script:Params = @{}
|
$script:Params = @{}
|
||||||
|
|||||||
Reference in New Issue
Block a user