Conversation
shammu1
requested review from
Sydney Smith (SydneyhSmith),
Aditya Patwardhan (adityapatwardhan),
alerickson and
Anam Navied (anamnavi)
as code owners
September 14, 2026 18:44
|
Azure Pipelines: There may be pipelines that require an authorized user to comment /azp run to run. |
There was a problem hiding this comment.
🟡 Changes recommended
The 401 diagnostic and URI reuse need correction, and regression tests are missing for the new messages.
Get a fresh assessment by requesting another Copilot review.
Pull request overview
Improves PSGallery publishing diagnostics for authentication, authorization, and duplicate-package failures.
Changes:
- Exposes the canonical PSGallery URI.
- Adds custom 401, 403, and 409 error handling.
- Extracts package identity for conflict diagnostics.
File summaries
| File | Description |
|---|---|
src/code/RepositorySettings.cs |
Exposes the PSGallery URI constant. |
src/code/PublishHelper.cs |
Adds package identity extraction and PSGallery-specific errors. |
Review details
Suppressed comments (9)
src/code/PublishHelper.cs:787
- The custom PSGallery 403 text has duplicated punctuation: the reason already ends with a period inside the parentheses, and the string adds another period after
). Since this PR is intended to expose the exact reason phrase, remove the trailing period outside the closing parenthesis.
new ArgumentException($"Could not publish to repository '{repoName}'. Response status code does not indicate success: 403 (The specified API key is invalid, has expired, or does not have permission to access the specified package.)."),
src/code/PublishHelper.cs:811
- The 409 message has the same duplicated punctuation (
modified.).), so the package-conflict reason is not emitted as an exact sentence. Remove the extra period after the closing parenthesis.
$"(A package with id '{packageName}' and version '{packageVersion}' already exists and cannot be modified.).",
src/code/PublishHelper.cs:750
- Please add a CI test for the PSGallery
Unauthorizedpath that asserts the exception text, not only the error ID. No existing test exercises this new branch, so the intended credential/API-key diagnostic could regress while the current status-code assertion still passes.
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)."),
"401Error",
src/code/PublishHelper.cs:787
- The existing incorrect-API-key PSGallery test checks only
FullyQualifiedErrorId, so it does not verify this newly introduced detailed 403 message. Please assert the full exception text here to protect the exact diagnostic promised by the PR.
else if (isPSGallery && e.Message.Contains("Forbidden"))
{
// For AKS Exception
error = new ErrorRecord(
new ArgumentException($"Could not publish to repository '{repoName}'. Response status code does not indicate success: 403 (The specified API key is invalid, has expired, or does not have permission to access the specified package.)."),
src/code/PublishHelper.cs:807
- Please add coverage for publishing the same package ID/version twice and assert that the 409 message contains the package identity. This new path depends on
PackageArchiveReaderand is otherwise untested, so both the duplicate detection diagnostic and identity extraction can regress unnoticed.
if (isPSGallery && e.Message.Contains("Conflict"))
{
// For AKS Exception
string packageName = _pkgName ?? "unknown";
string packageVersion = _pkgVersion?.ToNormalizedString() ?? "unknown";
src/code/PublishHelper.cs:748
- This comment says the branch handles an AKS exception, but the condition is explicitly for PSGallery. Please correct it so the error-handling rationale is not misleading to future maintainers.
// For AKS Exception
src/code/PublishHelper.cs:785
- This comment says the branch handles an AKS exception, but the condition is explicitly for PSGallery. Please correct it so the error-handling rationale is not misleading to future maintainers.
// For AKS Exception
src/code/PublishHelper.cs:805
- This comment says the branch handles an AKS exception, but the condition is explicitly for PSGallery. Please correct it so the error-handling rationale is not misleading to future maintainers.
// For AKS Exception
src/code/RepositorySettings.cs:28
- This exposes a shared constant, but
RegisterPSResourceRepository.cs:34still declares the same PSGallery URI separately. That leaves registration and the new PSGallery error classification with two sources of truth that can silently diverge when the endpoint changes; update the repository registration code to use this constant as well.
internal const string PSGalleryRepoUri = "https://www.powershellgallery.com/api/v2";
- Files reviewed: 2/2 changed files
- Comments generated: 2
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| 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)."), |
Comment on lines
+803
to
+807
| if (isPSGallery && e.Message.Contains("Conflict")) | ||
| { | ||
| // For AKS Exception | ||
| string packageName = _pkgName ?? "unknown"; | ||
| string packageVersion = _pkgVersion?.ToNormalizedString() ?? "unknown"; |
Collaborator
Author
|
/azp run |
|
Azure Pipelines: Successfully started running 1 pipeline(s). |
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.