Add custom exception messages for PSGallery - #2038
Merged
Merged
Conversation
shammu1
requested review from
Sydney Smith (SydneyhSmith),
Aditya Patwardhan (adityapatwardhan),
alerickson and
Anam Navied (anamnavi)
as code owners
September 14, 2026 20:46
|
Azure Pipelines: There may be pipelines that require an authorized user to comment /azp run to run. |
Collaborator
Author
|
/azp run |
|
Azure Pipelines: Successfully started running 1 pipeline(s). |
There was a problem hiding this comment.
🟡 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
.nupkgfiles. - 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 unrelatedAn API key must be providedreason. The precedingContains("API")branch already handles the missing-key response, so a bad credential is currently reported with the wrong cause; preservee.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 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)."), |
Collaborator
Author
|
/azp run |
|
Azure Pipelines: Successfully started running 1 pipeline(s). |
shammu1
force-pushed
the
shammu/aksexceptions
branch
from
September 16, 2026 20:11
f915f18 to
2355466
Compare
Collaborator
Author
|
/azp run |
|
Azure Pipelines: Successfully started running 1 pipeline(s). |
14 tasks
alerickson
approved these changes
Sep 16, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
.h,.cpp,.cs,.ps1and.psm1files have the correct copyright headerWIP:or[ WIP ]to the beginning of the title (theWIPbot will keep its status check atPendingwhile the prefix is present) and remove the prefix when the PR is ready.