Skip to content

Add error handling for registry key creation to diagnose access failures#4

Open
ib-bsb-br with Copilot wants to merge 2 commits into
codex/refactor-powershell-script-for-correctness-efgqv6from
copilot/sub-pr-2-again
Open

Add error handling for registry key creation to diagnose access failures#4
ib-bsb-br with Copilot wants to merge 2 commits into
codex/refactor-powershell-script-for-correctness-efgqv6from
copilot/sub-pr-2-again

Conversation

Copilot AI commented Nov 1, 2025

Copy link
Copy Markdown
Contributor

The script failed with "Requested registry access is not allowed" when creating registry keys at HKLM:\Software\PwshSetup, even when running as Administrator. This can occur due to WOW64 registry redirection or insufficient permissions.

Changes

  • Wrap registry key creation in try-catch with existence checks
  • Add detailed error messages identifying WOW64 redirection and permission issues
  • Use -ErrorAction Stop for explicit failure handling
# Before
New-Item -Path $RegistryBase -Force | Out-Null
New-Item -Path $StepsKey -Force | Out-Null

# After
try {
    if (-not (Test-Path $RegistryBase)) {
        New-Item -Path $RegistryBase -Force -ErrorAction Stop | Out-Null
    }
    if (-not (Test-Path $StepsKey)) {
        New-Item -Path $StepsKey -Force -ErrorAction Stop | Out-Null
    }
    Write-Log "Registry keys initialized successfully." 'INFO'
} catch {
    Write-Log "Failed to create registry keys in HKLM:\Software\PwshSetup: $($_.Exception.Message)" 'ERROR'
    Write-Log "This may be due to insufficient permissions or WOW64 registry redirection." 'ERROR'
    Write-Log "Please run as Administrator with elevated privileges, or check registry permissions." 'ERROR'
    throw "Registry access denied. Exit:1"
}

This provides actionable diagnostics when registry access fails rather than a cryptic system error.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.


Summary by cubic

Fixed verification log rendering for scoped variables and added safe registry key initialization with clear errors. This improves troubleshooting during Sandbox setup and validation.

  • Bug Fixes
    • Corrected string interpolation for $script:, $env:, and hashtable values in Write-Log/Write-Verbose.
    • Guarded creation of HKLM:\Software\PwshSetup keys with explicit error logging and guidance; standardized LogonCommand path display in verification.

Written for commit a1a5098. Summary will update automatically on new commits.

Co-authored-by: ib-bsb-br <182176521+ib-bsb-br@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix scoped variable formatting in verification log Add error handling for registry key creation to diagnose access failures Nov 1, 2025
Copilot AI requested a review from ib-bsb-br November 1, 2025 22:35
@ib-bsb-br ib-bsb-br marked this pull request as ready for review November 1, 2025 22:38
Copilot AI review requested due to automatic review settings November 1, 2025 22:38

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

I'm unable to provide a complete PR overview as the PR metadata section is empty. To conduct a thorough review, I would need:

  • The pull request title and description
  • Diffs showing the changed files with added/removed lines
  • Context about what files were modified
  • Information about the purpose of the changes

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@ib-bsb-br

Copy link
Copy Markdown
Owner

@gemini-code-assist review

@codex review

/copilot review

/gemini review

/codex review

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request effectively addresses the issue of unhandled exceptions during registry key creation by introducing a try-catch block. This will provide much clearer diagnostics for users facing permission issues. My review includes a couple of suggestions to simplify the implementation and improve the clarity of the error handling, making the script more robust and maintainable.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Keep them coming!

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 1 file

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants