forcedotcom / cli

Salesforce CLI
https://developer.salesforce.com/docs/atlas.en-us.sfdx_cli_reference.meta/sfdx_cli_reference/
BSD 3-Clause "New" or "Revised" License
494 stars 78 forks source link

"URI malformed" error when execute "sf project retrieve start" or "sf project reset tracking" #2624

Closed Ewaken closed 9 months ago

Ewaken commented 10 months ago

Summary

Hello, I use scratch orgs on my project and I had the error "URI malformed" on several sf commands:

I found a workaround to avoid this error, I had this stack trace when I executed these commands with "--dev-debug" ("sf project reset tracking --dev-debug" here) :

Error (1): URI malformed

*** Internal Diagnostic ***

URIError: URI malformed
    at decodeURIComponent (<anonymous>)
    at getDecodedKeyIfSourceMembersHas (C:\Users\*****\AppData\Roaming\npm\node_modules\@salesforce\cli\node_modules\@salesforce\source-tracking\lib\shared\remoteSourceTrackingService.js:439:29)
    at RemoteSourceTrackingService.getSourceMember (C:\Users\*****\AppData\Roaming\npm\node_modules\@salesforce\cli\node_modules\@salesforce\source-tracking\lib\shared\remoteSourceTrackingService.js:373:36)
    at C:\Users\*****\AppData\Roaming\npm\node_modules\@salesforce\cli\node_modules\@salesforce\source-tracking\lib\shared\remoteSourceTrackingService.js:313:39
    at Array.forEach (<anonymous>)
    at RemoteSourceTrackingService.trackSourceMembers (C:\Users\*****\AppData\Roaming\npm\node_modules\@salesforce\cli\node_modules\@salesforce\source-tracking\lib\shared\remoteSourceTrackingService.js:309:23)
    at RemoteSourceTrackingService.reset (C:\Users\*****\AppData\Roaming\npm\node_modules\@salesforce\cli\node_modules\@salesforce\source-tracking\lib\shared\remoteSourceTrackingService.js:152:20)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async SourceTracking.resetRemoteTracking (C:\Users\*****\AppData\Roaming\npm\node_modules\@salesforce\cli\node_modules\@salesforce\source-tracking\lib\sourceTracking.js:389:30)
    at async Promise.all (index 0)
******

Then, I can try catch this block of code as follow, and everything work just fine:

function getDecodedKeyIfSourceMembersHas({ key, sourceMembers, logger, }) {
    try {
        const originalKeyDecoded = decodeURIComponent(key);
        const match = Array.from(sourceMembers.keys()).find((memberKey) => decodeURIComponent(memberKey) === originalKeyDecoded);
        if (match) {
            logger.debug(`${match} matches already tracked member: ${key}`);
            return match;
        }
    }catch(e) {
    }
    return key;
}

Expected result

No error thrown

Actual result

"URI malformed" Error

System Information

I used shell terminal

{
  "architecture": "win32-x64",
  "cliVersion": "@salesforce/cli/2.22.7",
  "nodeVersion": "node-v20.10.0",
  "osVersion": "Windows_NT 10.0.19045",
  "rootPath": "C:\\Users\\*****\\AppData\\Roaming\\npm\\node_modules\\@salesforce\\cli",
  "shell": "cmd.exe",
  "pluginVersions": [
    "@oclif/plugin-autocomplete 3.0.3 (core)",
    "@oclif/plugin-commands 3.0.7 (core)",
    "@oclif/plugin-help 6.0.8 (core)",
    "@oclif/plugin-not-found 3.0.5 (core)",
    "@oclif/plugin-plugins 4.1.10 (core)",
    "@oclif/plugin-search 1.0.8 (core)",
    "@oclif/plugin-update 4.1.5 (core)",
    "@oclif/plugin-version 2.0.9 (core)",
    "@oclif/plugin-warn-if-update-available 3.0.6 (core)",
    "@oclif/plugin-which 3.0.12 (core)",
    "@salesforce/cli 2.22.7 (core)",
    "apex 3.0.9 (core)",
    "auth 3.0.12 (core)",
    "community 3.0.7 (user)",
    "data 3.0.6 (core)",
    "deploy-retrieve 2.2.6 (core)",
    "info 3.0.8 (core)",
    "limits 3.0.6 (core)",
    "marketplace 1.0.11 (core)",
    "org 3.1.2 (core)",
    "packaging 1.27.10 (core)",
    "schema 3.0.8 (core)",
    "settings 2.0.9 (core)",
    "sobject 1.0.6 (core)",
    "source 3.0.3 (core)",
    "telemetry 3.1.6 (core)",
    "templates 56.0.4 (core)",
    "trust 3.2.0 (core)",
    "user 3.1.1 (core)",
    "@salesforce/sfdx-plugin-lwc-test 1.1.1 (user)",
    "@salesforce/sfdx-scanner 3.19.0 (user)"
  ]
}

Additional information

github-actions[bot] commented 10 months ago

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.

cristiand391 commented 10 months ago

@Ewaken a few questions: 1) are you able to repro the error with previous version of the CLI? 2) can you see the value of the key that's getting the getDecodedKeyIfSourceMembersHas function?

Ewaken commented 9 months ago

@Ewaken a few questions:

  1. are you able to repro the error with previous version of the CLI?
  2. can you see the value of the key that's getting the getDecodedKeyIfSourceMembersHas function?
  1. Yes I had this problem from few months and I'm not the only one in my team.
  2. Yes I have a lot of keys in error: ApexClasses, CustomLabels, Custom Metadatas... e.g. CustomMetadata__invalid_NAF_codes.X4761Z
shetzel commented 9 months ago

I don't see an error when running decodeURIComponent('CustomMetadata__invalid_NAF_codes.X4761Z'). Regardless, I'll mark it as a bug and get a fix going.

git2gus[bot] commented 9 months ago

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