Skip to content

@W-24017820@ fix(package-convert): actionable error when Dev Hub lacks 2GP - #928

Closed
agayakwad-salesforce wants to merge 1 commit into
mainfrom
t/2gp-readiness/w-24017820/actionable-error-for-convert-without-2gp
Closed

agayakwad-salesforce wants to merge 1 commit into
mainfrom
t/2gp-readiness/w-24017820/actionable-error-for-convert-without-2gp

Conversation

@agayakwad-salesforce

Copy link
Copy Markdown
Collaborator

@W-24017820@

What does this PR do?

Makes sf package convert (1GP → 2GP conversion) fail with a clear, actionable
error when run against a Dev Hub org that does not have second-generation managed
packaging enabled.

Previously, the very first server call in the convert flow — the Package2
tooling query in findOrCreatePackage2 — had no error handling and did not route
through the error-massaging utilities. When the Dev Hub lacked 2GP, the raw
tooling-API error propagated straight to the user:

INVALID_TYPE: sObject type 'Package2' is not supported. If you are attempting to
use a custom object, be sure to append the '__c' after the entity name. Please
reference your WSDL or the describe call for the appropriate names.

There was no guidance telling the user the real problem: 2GP packaging isn't
enabled on their Dev Hub.

What's the fix?

In src/package/packageConvert.ts:

  • Primary: Wrap the Package2 tooling query in findOrCreatePackage2 in a
    try/catch. When the error indicates Package2 is not supported, throw the
    new, actionable convertPackagingNotEnabledOnOrg message instead of the raw
    error. Any other error is rethrown unchanged.
  • Secondary: Guard the Package2 create path — if the create result reports
    the same "not supported" condition, throw the actionable message rather than
    the generic combineSaveErrors output.
  • Add a small shared helper, isPackage2NotSupportedError, that detects the
    condition from either an Error or a jsforce SaveError object. It matches on
    a substring (sObject type 'Package2' is not supported.) because the full
    server message may append custom-object WSDL boilerplate — consistent with the
    existing handling in packageVersionRetrieve.ts.

New user-facing message (messages/package_version_create.md):

Can't convert package. The org you specified doesn't have the required
second-generation packaging permission enabled. Enable this permission on your
Dev Hub org, and try again.

This mirrors the existing packagingNotEnabledOnOrg message used by
sf package version retrieve, keeping behavior consistent across commands.

Before / After

Before

Error (INVALID_TYPE):
SELECT Id, Name FROM Package2 WHERE ConvertedFromPackageId
                     ^
ERROR at Row:1:Column:22
sObject type 'Package2' is not supported. ...

After

Error (ConvertPackagingNotEnabledOnOrgError): Can't convert package. The org you
specified doesn't have the required second-generation packaging permission
enabled. Enable this permission on your Dev Hub org, and try again.

The raw INVALID_TYPE / "is not supported" text no longer leaks to the user
(verified in both human-readable and --json output).

Scope

This change is intentionally limited to the convert flow. The native
sf package version create path is out of scope for this PR and is unchanged.

Testing

  • Added unit tests in test/package/packageConvert.test.ts:
    • findOrCreatePackage2 throws the actionable error when the Package2 query
      fails with "not supported".
    • findOrCreatePackage2 throws the actionable error when the Package2
      create reports "not supported".
    • convertPackage surfaces the actionable error (end-to-end propagation).
    • Each asserts the exact actionable message and that the raw
      is not supported text does not leak.
  • Unit tests: packageConvert.test.ts — 25 passing.
  • Lint and Prettier: clean on all changed files.
  • Manual end-to-end verification against a locally-provisioned Dev Hub with
    2GP disabled: confirmed the convert command returns
    ConvertPackagingNotEnabledOnOrgError with no raw INVALID_TYPE leak in both
    default and --json output.

Files changed

  • src/package/packageConvert.ts
  • messages/package_version_create.md
  • test/package/packageConvert.test.ts

Issues

@W-24017820@

@agayakwad-salesforce
agayakwad-salesforce requested a review from a team as a code owner September 4, 2026 16:29
@salesforce-cla

salesforce-cla Bot commented Sep 4, 2026

Copy link
Copy Markdown

Thanks for the contribution! It looks like @agayakwad-salesforce is an internal user so signing the CLA is not required. However, we need to confirm this.

@github-actions

github-actions Bot commented Sep 4, 2026

Copy link
Copy Markdown

This PR lacks any commits of the 'fix' or 'feat' type, and therefore will not trigger a release. To silence all further warnings, react to this warning comment (or any other) with the 👀 emoji.

NOTE: If your repo uses squash commits, make sure to add the appropriate conventional commit prefix (e.g., 'fix:', 'feat:', 'chore:', etc) in the squash commit message.

… 2GP

When running sf package convert against a Dev Hub without second-generation
managed packaging enabled, the Package2 tooling query in findOrCreatePackage2
threw a raw INVALID_TYPE "sObject type 'Package2' is not supported" error with
no actionable guidance.

Wrap the Package2 query and the Package2 create path so the "not supported"
error is surfaced as a clear, actionable message (convertPackagingNotEnabledOnOrg),
consistent with the existing handling in package version retrieve.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@agayakwad-salesforce
agayakwad-salesforce force-pushed the t/2gp-readiness/w-24017820/actionable-error-for-convert-without-2gp branch from ad85325 to d5ec8f1 Compare September 7, 2026 11:34
@agayakwad-salesforce

Copy link
Copy Markdown
Collaborator Author

This PR lacks any commits of the 'fix' or 'feat' type, and therefore will not trigger a release. To silence all further warnings, react to this warning comment (or any other) with the 👀 emoji.

NOTE: If your repo uses squash commits, make sure to add the appropriate conventional commit prefix (e.g., 'fix:', 'feat:', 'chore:', etc) in the squash commit message.

resolved

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant