feat(registry): implement automatic registry rollback on execution failure#613
feat(registry): implement automatic registry rollback on execution failure#613HetCreep wants to merge 2 commits into
Conversation
|
Heya, I do like this idea, I'll take a look at this soon when I have time. Thanks! |
8b5df67 to
328a6e3
Compare
|
@coderabbitai review |
✅ Action performedReview finished.
|
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
📝 WalkthroughWalkthrough
ChangesAutomatic Registry Rollback on Execution Failure
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@Scripts/Features/ExecuteChanges.ps1`:
- Around line 206-252: The ImportRegistryFile function call within the undo
operations section records failures in $script:RegistryImportFailures without
throwing an exception, which prevents the catch block from executing and rolling
back earlier registry writes. To fix this, either modify ImportRegistryFile to
throw an exception when it increments the failure counter, or add a check inside
the try block after the ImportRegistryFile call to throw an exception if
$script:RegistryImportFailures has been incremented. This ensures that registry
import failures trigger the catch block for proper rollback handling.
- Line 255: The Test-Path check for the backup file on line 255 needs to use the
-LiteralPath parameter instead of treating the path as a pattern. Change the
condition that checks "if ($backupFile -and (Test-Path $backupFile))" to use
"-LiteralPath $backupFile" in the Test-Path call, which will prevent wildcard
characters like brackets from being interpreted as patterns and ensure the
rollback attempt is not skipped for valid paths containing these characters.
This should match the approach already used in the Load-RegistryBackupFromFile
function.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 45c65df7-0016-44ac-a8f1-82e3cb495fe3
📒 Files selected for processing (1)
Scripts/Features/ExecuteChanges.ps1
71ef6c2 to
d4a57cb
Compare
There was a problem hiding this comment.
🧹 Nitpick comments (1)
Scripts/Features/ExecuteChanges.ps1 (1)
287-290: 💤 Low valueDead code: this warning block is now unreachable.
With the new failure detection at lines 242-244 and 266-268 throwing when
$script:RegistryImportFailuresincreases, this block can never execute with a non-zero failure count:
- If failures occur → exception thrown → function exits before reaching here
- If no failures →
$script:RegistryImportFailuresremains 0 → condition is falseConsider removing this block since failure messaging is now handled by the exception path.
♻️ Suggested removal
} throw } - -if ($script:RegistryImportFailures -gt 0) { - Write-Host "" - Write-Host "$($script:RegistryImportFailures) registry import change(s) failed. See output above for details." -ForegroundColor Yellow -} }🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@Scripts/Features/ExecuteChanges.ps1` around lines 287 - 290, The warning block that checks if $script:RegistryImportFailures is greater than 0 is now unreachable dead code. With the new failure detection logic that throws exceptions when $script:RegistryImportFailures increases (added in the preceding validation blocks), the function will exit via exception before reaching this warning block, so the condition can never be true. Remove the entire if block (the condition check and the Write-Host statements within it) since failure messaging is now handled by the exception throwing paths in the earlier validation logic.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@Scripts/Features/ExecuteChanges.ps1`:
- Around line 287-290: The warning block that checks if
$script:RegistryImportFailures is greater than 0 is now unreachable dead code.
With the new failure detection logic that throws exceptions when
$script:RegistryImportFailures increases (added in the preceding validation
blocks), the function will exit via exception before reaching this warning
block, so the condition can never be true. Remove the entire if block (the
condition check and the Write-Host statements within it) since failure messaging
is now handled by the exception throwing paths in the earlier validation logic.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: cf61878b-3d83-4033-aead-398f21c3b0be
📒 Files selected for processing (1)
Scripts/Features/ExecuteChanges.ps1
d4a57cb to
8352468
Compare
8352468 to
7af95d8
Compare
|
Heads-up on the merge conflict here: #641 refactored Since it's the registry-rollback safety path and I can't run-test the restore on my end, I'd rather not force-push an untested rewrite of it. Would you prefer I redo it against the new structure (you'd want to verify the rollback/restore path before merge), or would you rather fold it into your own refactor? Either works for me -- just didn't want to decide that for you. |
Resolves #612
Changes
Summary by CodeRabbit
New-RegistrySettingsBackup, wrapping the “execute actionable parameters” and “execute undo operations” loops in atry/catch, and triggering an automatic rollback viaRestore-RegistryBackupStatewhen parameter execution fails or when$script:RegistryImportFailuresincreases during either phase; rollback errors are logged and the original failure is re-thrown.