Skip to content

Add custom exception messages for PSGallery - #2038

Merged
shammu1 merged 1 commit into
masterfrom
shammu/aksexceptions
Sep 16, 2026
Merged

shammu1 merged 1 commit into
masterfrom
shammu/aksexceptions

Conversation

@shammu1

@shammu1 shammu1 commented Sep 14, 2026

Copy link
Copy Markdown
Collaborator

PR Summary

This pull request enhances error handling and diagnostics when publishing packages to the PowerShell Gallery (PSGallery), making it easier to identify and troubleshoot authentication and permission issues.

PR Context

This PR is needed for PSResourceGET to provide the users the exceptions messages with exact reason phrase for PSGallery.

PR Checklist

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
There may be pipelines that require an authorized user to comment /azp run to run.

@shammu1 shammu1 changed the title Add custom exception messages for PSGallery- #2037 Add custom exception messages for PSGallery Sep 14, 2026
@shammu1

shammu1 commented Sep 14, 2026

Copy link
Copy Markdown
Collaborator Author

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).

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.

🟡 Changes recommended

Add coverage validating the new PSGallery diagnostic messages.

Get a fresh assessment by requesting another Copilot review.

Pull request overview

This PR improves PSGallery publishing diagnostics with clearer authentication, permission, and duplicate-package errors.

Changes:

  • Exposes the PSGallery URI.
  • Extracts package identity from .nupkg files.
  • Adds custom handling for HTTP 401, 403, and 409 responses.
File summaries
File Summary Findings
src/code/RepositorySettings.cs Exposes the PSGallery URI constant. None
src/code/PublishHelper.cs Adds package identity extraction and PSGallery-specific diagnostics. Moderate: add tests covering the exact 401, 403, and 409 messages, including duplicate-package formatting.
Review details

Suppressed comments (1)

src/code/PublishHelper.cs:749

  • This branch is selected for 401 Unauthorized, but the message hard-codes the unrelated An API key must be provided reason. The preceding Contains("API") branch already handles the missing-key response, so a bad credential is currently reported with the wrong cause; preserve e.Message (or use the actual Unauthorized reason) here.
                        error = new ErrorRecord(new ArgumentException($"Could not publish to repository '{repoName}'. The Credential provided was incorrect. Exception: Response status code does not indicate success: 401 (An API key must be provided)."),
  • Files reviewed: 2/2 changed files
  • Comments generated: 1
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread src/code/PublishHelper.cs
Comment on lines +746 to +749
else if (isPSGallery && e.Message.Contains("Unauthorized"))
{
// For AKS Exception
error = new ErrorRecord(new ArgumentException($"Could not publish to repository '{repoName}'. The Credential provided was incorrect. Exception: Response status code does not indicate success: 401 (An API key must be provided)."),
@shammu1

shammu1 commented Sep 15, 2026

Copy link
Copy Markdown
Collaborator Author

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).

@shammu1
shammu1 force-pushed the shammu/aksexceptions branch from f915f18 to 2355466 Compare September 16, 2026 20:11
@shammu1

shammu1 commented Sep 16, 2026

Copy link
Copy Markdown
Collaborator Author

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).

@shammu1
shammu1 merged commit 63a1093 into master Sep 16, 2026
12 checks passed
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