fix(checkup): Catch Get-MpPreference exception#6584
fix(checkup): Catch Get-MpPreference exception#6584Ninja3047 wants to merge 1 commit intoScoopInstaller:developfrom
Conversation
WalkthroughThe change adds error handling to Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~15 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (1)
lib/diagnostic.ps1 (1)
9-29: Consider cachingGet-MpPreferenceresult to avoid duplicate calls.
Get-MpPreferenceis called twice (lines 10 and 16). This is inefficient and could fail on the second call even if the first succeeded. Store the result in a variable.♻️ Suggested refactor
if (Test-CommandAvailable Get-MpPreference) { try { - if ((Get-MpPreference -Erroraction Stop).DisableRealtimeMonitoring) { return $true } + $mpPreference = Get-MpPreference -ErrorAction Stop + if ($mpPreference.DisableRealtimeMonitoring) { return $true } if ($defender -and $defender.Status) { if ($defender.Status -eq [System.ServiceProcess.ServiceControllerStatus]::Running) { $installPath = $scoopdir; if ($global) { $installPath = $globaldir; } - $exclusionPath = (Get-MpPreference -Erroraction Stop).ExclusionPath + $exclusionPath = $mpPreference.ExclusionPath if (!($exclusionPath -contains $installPath)) {
📜 Review details
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
lib/diagnostic.ps1
🔇 Additional comments (1)
lib/diagnostic.ps1 (1)
26-28: Good error handling for the reported issue.The catch block correctly handles
CimException(HRESULT 0x800106ba) that occurs when Windows Defender is unavailable. Returning$trueis appropriate since the check cannot complete and should not block other diagnostics.
Description
Catches
Get-MpPreferenceerror and returns gracefullyMotivation and Context
Closes: #6583
How Has This Been Tested?
Tested by running
scoop checkupon my machine.Checklist:
developbranch.Summary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings.