Skip to content

[BUG]: An unknown alias in SF_TARGET_ORG fails with NoDefaultEnvError instead of NamedOrgNotFoundError #3697

Backlog

Description

@damian-lewkowicz

Before You Submit

  • I'm using the latest version of Salesforce CLI
  • I've searched the existing issues
  • I've run sf doctor to diagnose common issues

Related Issue

No response

Command

sf data query

Org Type

Production

Did this work before?

Yes, this is a regression

Last Working Version

No response

Summary

When SF_TARGET_ORG names an org that the CLI doesn't know (e.g. a mistyped alias), commands ignore it and fail with NoDefaultEnvError, as if no target org were set. The same value passed with --target-org fails with NamedOrgNotFoundError, which names the wrong alias and suggests a close match.

Repository to Reproduce

No response

Steps to reproduce

  1. Run from a directory without a project default org:

    SF_TARGET_ORG=no-such-alias sf data query -q "SELECT Id FROM Organization" --json
  2. Compare with:

    sf data query -q "SELECT Id FROM Organization" --target-org no-such-alias --json

Expected Result

Both fail with NamedOrgNotFoundError: No authorization information found for no-such-alias.

Actual Result

Step 1 fails with:

NoDefaultEnvError: No default environment found. Use -o or --target-org to specify an environment.

The error hides the value set in SF_TARGET_ORG, so the user looks for a missing default org instead of a wrong alias. With a project or global default org set, it may target that org instead (not verified).

Error Message

System Information

{
  "architecture": "darwin-arm64",
  "cliVersion": "@salesforce/cli/2.159.7",
  "nodeVersion": "node-v24.22.1",
  "osVersion": "Darwin 27.2.0",
  "rootPath": "/opt/homebrew/lib/node_modules/@salesforce/cli",
  "shell": "zsh",
  "pluginVersions": [
    "@oclif/plugin-autocomplete 4.0.6 (core)",
    "@oclif/plugin-commands 5.0.12 (core)",
    "@oclif/plugin-help 7.0.7 (core)",
    "@oclif/plugin-not-found 4.0.7 (core)",
    "@oclif/plugin-plugins 7.0.16 (core)",
    "@oclif/plugin-search 2.0.12 (core)",
    "@oclif/plugin-update 5.0.10 (core)",
    "@oclif/plugin-version 3.0.10 (core)",
    "@oclif/plugin-warn-if-update-available 4.0.5 (core)",
    "@oclif/plugin-which 4.0.10 (core)",
    "@salesforce/cli 2.159.7 (core)",
    "agent 2.3.0 (core)",
    "apex 4.4.7 (core)",
    "api 2.0.29 (core)",
    "auth 6.0.5 (core)",
    "code-analyzer 5.16.0 (user) published 97 days ago (Wed Aug 26 2026)",
    "data 5.1.28 (core)",
    "deploy-retrieve 4.3.3 (core)",
    "info 4.0.26 (core)",
    "limits 4.0.6 (core)",
    "marketplace 2.0.28 (core)",
    "org 7.0.15 (core)",
    "packaging 3.0.17 (user) published 35 days ago (Mon Oct 26 2026)",
    "schema 4.0.17 (core)",
    "settings 3.0.25 (core)",
    "signups 3.0.13 (user) published 30 days ago (Sun Nov 01 2026) (latest is 3.0.18)",
    "sobject 2.0.26 (core)",
    "telemetry 4.2.4 (core)",
    "templates 57.6.1 (core)",
    "trust 4.1.4 (core)",
    "user 6.0.13 (core)",
    "sf-git-merge-driver 2.2.0 (user) published 9 days ago (Sat Nov 21 2026)",
    "sfdmu 5.8.0 (user) published 150 days ago (Fri Jul 03 2026)",
    "sfdx-browserforce-plugin 7.2.2 (user) published 12 days ago (Wed Nov 18 2026)",
    "sfdx-git-delta 6.45.1 (user) published 158 days ago (Fri Jun 26 2026)",
    "sfdx-hardis 8.28.0 (user) published 1 days ago (Sun Nov 29 2026)"
  ]
}

Additional Information

No response

Screenshots or Log Files

No response

Activity

  1. added
    investigating
    on Dec 1, 2026
  2. added
    regression
    on Dec 1, 2026
  3. github-actions commented on Dec 1, 2026

    @github-actions

    Thank you for filing this issue. We appreciate your feedback and will review the issue as soon as possible. Remember, however, that GitHub isn't a mechanism for receiving support under any agreement or SLA. If you require immediate assistance, contact Salesforce Customer Support.

  4. added
    validated
    on Dec 1, 2026
  5. git2gus commented on Dec 1, 2026

    @git2gus

    This issue has been linked to a new work item: W-25087840

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    investigatingregressionvalidated

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions