From 0614ffe68fa402a8bfe74f00fca095d92ac0de7a Mon Sep 17 00:00:00 2001 From: HetCreep Date: Wed, 1 Jul 2026 03:28:51 +0700 Subject: [PATCH] fix(restore-gui): surface registry-backup load failures to the user Picking a malformed or invalid backup .json in the Restore Backup dialog threw out of the WPF button-click handler. Because the throw originates inside a dispatcher callback, it bypassed every surrounding try/catch (those sit on a different call stack than the dispatcher-invoked handler) and was caught only by the dispatcher's global unhandled-exception handler, which writes a console warning and marks it handled -- invisible in the GUI. The dialog just sat there doing nothing. Wrap the load + overview render in try/catch and show the error via the existing Show-MessageBox helper, matching the convention already used in this file. --- Scripts/GUI/Show-RestoreBackupDialog.ps1 | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/Scripts/GUI/Show-RestoreBackupDialog.ps1 b/Scripts/GUI/Show-RestoreBackupDialog.ps1 index 8cacede..f108c72 100644 --- a/Scripts/GUI/Show-RestoreBackupDialog.ps1 +++ b/Scripts/GUI/Show-RestoreBackupDialog.ps1 @@ -295,9 +295,19 @@ function Show-RestoreBackupDialog { } Write-Host "Backup file selected: $($openDialog.FileName)" - $selectedBackup = Load-RegistryBackupFromFile -FilePath $openDialog.FileName - if (-not (& $showRegistryOverview -SelectedBackup $selectedBackup -SelectedBackupFilePath $openDialog.FileName)) { + try { + $selectedBackup = Load-RegistryBackupFromFile -FilePath $openDialog.FileName + + if (-not (& $showRegistryOverview -SelectedBackup $selectedBackup -SelectedBackupFilePath $openDialog.FileName)) { + return + } + } + catch { + # Surface load/validation failures to the user. Without this, the throw escapes the + # button-click handler, is caught only by the dispatcher's global unhandled-exception + # handler (which merely writes a console warning), and the dialog silently does nothing. + Show-MessageBox -Owner $window -Title 'Invalid Backup File' -Message "The selected file could not be loaded as a registry backup:`n`n$($_.Exception.Message)" -Button 'OK' -Icon 'Error' | Out-Null return }