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.
This commit is contained in:
HetCreep 2026-07-01 03:28:51 +07:00
parent 26b313372b
commit 0614ffe68f
No known key found for this signature in database

View File

@ -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
}