Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unexpected error while executing anonymous apex. Cannot read properties of undefined (reading 'DebuggingInfo') #2630

Closed
gbutt-tr opened this issue Jan 3, 2024 · 8 comments
Labels
bug Issue or pull request that identifies or fixes a bug validated Version information for this issue has been validated

Comments

@gbutt-tr
Copy link

gbutt-tr commented Jan 3, 2024

Summary

Whenever I execute anonymous apex via sf apex run -f <file> I get this error:
Unexpected error while executing anonymous apex. Cannot read properties of undefined (reading 'DebuggingInfo')

JSON output of command
$ sf apex run -f ./scripts/apex/deleteScratchOrgData.apex --json

{
  "code": 1,
  "context": "Run",
  "commandName": "Run",
  "message": "Unexpected error while executing anonymous apex. Cannot read properties of undefined (reading 'DebuggingInfo')",
  "name": "Error",
  "status": 1,
  "stack": "Error: Unexpected error while executing anonymous apex. Cannot read properties of undefined (reading 'DebuggingInfo')\n    at ExecuteService.<anonymous> (/opt/homebrew/Cellar/nvm/0.39.5/versions/node/v18.17.1/lib/node_modules/@salesforce/cli/node_modules/@salesforce/apex-node/lib/src/execute/executeService.js:41:31)\n    at Generator.next (<anonymous>)\n    at fulfilled (/opt/homebrew/Cellar/nvm/0.39.5/versions/node/v18.17.1/lib/node_modules/@salesforce/cli/node_modules/@salesforce/apex-node/lib/src/execute/executeService.js:5:58)\n    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)",
  "exitCode": 1,
  "warnings": []
}

I was able to trace this issue to a specific line of code:
node_modules/@salesforce/apex-node/lib/src/execute/executeService.js:117:69
logs: soapResponse[types_1.soapEnv][types_1.soapHeader].DebuggingInfo.debugLog

When I JSON.stringify the soapResponse, I do not see any key called soapenv:Header. Here is the output I am seeing:

{
  "soapenv:Envelope": {
    "$": {
      "xmlns:soapenv": "http://schemas.xmlsoap.org/soap/envelope/",
      "xmlns": "http://soap.sforce.com/2006/08/apex",
      "xmlns:xsi": "http://www.w3.org/2001/XMLSchema-instance"
    },
    "soapenv:Body": {
      "executeAnonymousResponse": {
        "result": {
          "column": "-1",
          "compileProblem": {
            "$": {
              "xsi:nil": "true"
            }
          },
          "compiled": "true",
          "exceptionMessage": {
            "$": {
              "xsi:nil": "true"
            }
          },
          "exceptionStackTrace": {
            "$": {
              "xsi:nil": "true"
            }
          },
          "line": "-1",
          "success": "true"
        }
      }
    }
  }
}

I was able to workaround this issue by optional chaining soapenv:Header:
logs: soapResponse[types_1.soapEnv][types_1.soapHeader]?.DebuggingInfo.debugLog

Steps To Reproduce

Execute anonymous apex against a scratch org using sf apex run -f <file>

Expected result

Execution completed without error

Actual result

Execution throws an exception while parsing the soap response

System Information

{
  "architecture": "darwin-arm64",
  "cliVersion": "@salesforce/cli/2.21.8",
  "nodeVersion": "node-v18.17.1",
  "osVersion": "Darwin 22.6.0",
  "rootPath": "/opt/homebrew/Cellar/nvm/0.39.5/versions/node/v18.17.1/lib/node_modules/@salesforce/cli",
  "shell": "zsh",
  "pluginVersions": [
    "@oclif/plugin-autocomplete 3.0.2 (core)",
    "@oclif/plugin-commands 3.0.7 (core)",
    "@oclif/plugin-help 6.0.7 (core)",
    "@oclif/plugin-not-found 3.0.4 (core)",
    "@oclif/plugin-plugins 4.1.9 (core)",
    "@oclif/plugin-search 1.0.8 (core)",
    "@oclif/plugin-update 4.1.4 (core)",
    "@oclif/plugin-version 2.0.8 (core)",
    "@oclif/plugin-warn-if-update-available 3.0.5 (core)",
    "@oclif/plugin-which 3.0.11 (core)",
    "@salesforce/cli 2.21.8 (core)",
    "apex 3.0.8 (core)",
    "auth 3.0.10 (core)",
    "data 3.0.5 (core)",
    "deploy-retrieve 2.2.3 (core)",
    "info 3.0.7 (core)",
    "limits 3.0.5 (core)",
    "marketplace 1.0.10 (core)",
    "org 3.1.1 (core)",
    "packaging 1.26.1 (user)",
    "schema 3.0.8 (core)",
    "settings 2.0.9 (core)",
    "sobject 1.0.5 (core)",
    "source 3.0.3 (core)",
    "telemetry 3.1.4 (core)",
    "templates 56.0.4 (core)",
    "trust 3.1.2 (core)",
    "user 3.1.0 (core)"
  ]
}

Additional information

@gbutt-tr gbutt-tr added the investigating We're actively investigating this issue label Jan 3, 2024
Copy link

github-actions bot commented Jan 3, 2024

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.

@github-actions github-actions bot added the validated Version information for this issue has been validated label Jan 3, 2024
@cristiand391
Copy link
Member

Are you able to repro this with another org?

I looked at the library code and it always set this so the response the header containing the debug log, docs also mention there's a limit of 1000 request per day, after that request will work but not include the header.
https://developer.salesforce.com/docs/atlas.en-us.api.meta/api/sforce_api_header_debuggingheader.htm

@gbutt-tr
Copy link
Author

gbutt-tr commented Jan 3, 2024

@cristiand391
No I have not tried creating a new scratch org since I got this error (It takes awhile to do that).

I have noticed that error only manifests every now and again, but it is persistent once I start to hit it. It has become much more prevalent since I started using Illuminated Cloud for development. This link explains why it only happens sometimes and how to get it to go away (create a new scratch org).

This seems like a bug if there is a chance that the soapenv:Header may not be included in every response.

@cristiand391
Copy link
Member

This seems like a bug if there is a chance that the soapenv:Header may not be included in every response.

Agree, at least that's what the docs say if you pass that limit. I modified the library to make +1000 requests with the same org but it still gets the header so I can't exactly repro.

Will mark as bug to add a warning to mention the API limit but there's no workaround to get the logs in those cases.

@cristiand391 cristiand391 added bug Issue or pull request that identifies or fixes a bug and removed investigating We're actively investigating this issue labels Jan 3, 2024
Copy link

git2gus bot commented Jan 3, 2024

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

@gbutt-tr
Copy link
Author

gbutt-tr commented Jan 3, 2024

Thanks. I wish I had better info to reproduce it. I know I've seen it in at least two scratch orgs.

@gbutt-tr
Copy link
Author

gbutt-tr commented Jan 4, 2024

Update:

I am not getting the error today, same scratch org. I double-checked that my workaround was removed from the cli code.

More strong evidence that this issue was caused by reaching a 24-hour rolling limit.

@shetzel
Copy link
Contributor

shetzel commented Jan 16, 2024

Should have a fix in soon. forcedotcom/salesforcedx-apex#343

@mshanemc mshanemc closed this as completed Feb 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issue or pull request that identifies or fixes a bug validated Version information for this issue has been validated
Projects
None yet
Development

No branches or pull requests

4 participants