cli icon indicating copy to clipboard operation
cli copied to clipboard

ERROR running force:apex:test:run: Cannot read property 'message' of undefined

Open steals opened this issue 3 years ago • 3 comments

Summary

When I run sfdx force:apex:test:run --resultformat junit --codecoverage --testlevel RunLocalTests against developer org with namespace I get the following error:.

ERROR running force:apex:test:run:  Cannot read property 'message' of undefined 
*** Internal Diagnostic ***

TypeError: Cannot read property 'message' of undefined
    at /Users/steals/.local/share/sfdx/node_modules/salesforce-alm/dist/lib/apex/apexTestApi.js:534:65
From previous event:
    at runAsync (/Users/steals/.local/share/sfdx/node_modules/salesforce-alm/dist/lib/apex/apexTestApi.js:533:23)
    at ApexTestApi.runTests (/Users/steals/.local/share/sfdx/node_modules/salesforce-alm/dist/lib/apex/apexTestApi.js:602:20)
    at /Users/steals/.local/share/sfdx/node_modules/salesforce-alm/dist/lib/apex/apexTestCommand.js:80:33
    at processImmediate (internal/timers.js:456:21)
From previous event:
    at ApexTestCommand.execute (/Users/steals/.local/share/sfdx/node_modules/salesforce-alm/dist/lib/apex/apexTestCommand.js:80:14)
    at ApexTestRunCommand.execLegacyCommand (/Users/steals/.local/share/sfdx/node_modules/salesforce-alm/dist/ToolbeltCommand.js:149:43)
    at ApexTestRunCommand.run (/Users/steals/.local/share/sfdx/node_modules/salesforce-alm/dist/commands/force/apex/test/run.js:23:25)
    at ApexTestRunCommand._run (/Users/steals/.local/share/sfdx/node_modules/salesforce-alm/node_modules/@salesforce/command/lib/sfdxCommand.js:93:40)
    at Config.runCommand (/Users/steals/.local/share/sfdx/client/7.77.0-112dd7d412/node_modules/@oclif/config/lib/config.js:173:24)
    at Main.run (/Users/steals/.local/share/sfdx/client/7.77.0-112dd7d412/node_modules/@oclif/command/lib/main.js:27:9)
    at Main._run (/Users/steals/.local/share/sfdx/client/7.77.0-112dd7d412/node_modules/@oclif/command/lib/command.js:43:20)
    at Object.run (/Users/steals/.local/share/sfdx/client/7.77.0-112dd7d412/dist/cli.js:32:20)
Outer stack:
    at Function.wrap (/Users/steals/.local/share/sfdx/node_modules/salesforce-alm/node_modules/@salesforce/core/lib/sfdxError.js:171:27)
    at ApexTestRunCommand.catch (/Users/steals/.local/share/sfdx/node_modules/salesforce-alm/dist/ToolbeltCommand.js:248:46)
    at ApexTestRunCommand._run (/Users/steals/.local/share/sfdx/node_modules/salesforce-alm/node_modules/@salesforce/command/lib/sfdxCommand.js:97:13)
    at Config.runCommand (/Users/steals/.local/share/sfdx/client/7.77.0-112dd7d412/node_modules/@oclif/config/lib/config.js:173:24)
    at Main.run (/Users/steals/.local/share/sfdx/client/7.77.0-112dd7d412/node_modules/@oclif/command/lib/main.js:27:9)
    at Main._run (/Users/steals/.local/share/sfdx/client/7.77.0-112dd7d412/node_modules/@oclif/command/lib/command.js:43:20)
    at Object.run (/Users/steals/.local/share/sfdx/client/7.77.0-112dd7d412/dist/cli.js:32:20)
******

and one more error from --dev-debug

sfdx:connection DEBUG >>> Query start >>> +1ms
  sfdx:connection DEBUG SOQL = SELECT ApexTestClass.Id, ApexTestClass.Name, Coverage, TestMethodName, NumLinesCovered, ApexClassOrTrigger.Id, ApexClassOrTrigger.Name, NumLinesUncovered FROM ApexCodeCoverage +0ms
  sfdx:connection DEBUG request: {"method":"GET","url":"https://my-domain-namespace-dev-ed.my.salesforce.com/services/data/v50.0/tooling/query?q=SELECT%20ApexTestClass.Id%2C%20ApexTestClass.Name%2C%20Coverage%2C%20TestMethodName%2C%20NumLinesCovered%2C%20ApexClassOrTrigger.Id%2C%20ApexClassOrTrigger.Name%2C%20NumLinesUncovered%20FROM%20ApexCodeCoverage","headers":{"content-type":"application/json","user-agent":"sfdx toolbelt:"}} +0ms
  sfdx:connection DEBUG *** Query finished *** +9s
(node:54546) Warning: a promise was rejected with a non-error: [object Undefined]
Warning: a promise was rejected with a non-error: [object Undefined]
    at /Users/steals/.local/share/sfdx/node_modules/salesforce-alm/dist/lib/apex/apexTestApi.js:740:22
From previous event:
    at Object.construct (/Users/steals/.local/share/sfdx/client/7.77.0-112dd7d412/node_modules/@salesforce/lazy-require/lib/LazyLoader.js:186:36)
    at ApexTestApi.waitForResult (/Users/steals/.local/share/sfdx/node_modules/salesforce-alm/dist/lib/apex/apexTestApi.js:754:23)
    at runAsync (/Users/steals/.local/share/sfdx/node_modules/salesforce-alm/dist/lib/apex/apexTestApi.js:507:42)
    at ApexTestApi.runTests (/Users/steals/.local/share/sfdx/node_modules/salesforce-alm/dist/lib/apex/apexTestApi.js:602:20)
    at /Users/steals/.local/share/sfdx/node_modules/salesforce-alm/dist/lib/apex/apexTestCommand.js:80:33
    at processImmediate (internal/timers.js:456:21)
From previous event:
    at ApexTestCommand.execute (/Users/steals/.local/share/sfdx/node_modules/salesforce-alm/dist/lib/apex/apexTestCommand.js:80:14)
    at ApexTestRunCommand.execLegacyCommand (/Users/steals/.local/share/sfdx/node_modules/salesforce-alm/dist/ToolbeltCommand.js:149:43)
    at ApexTestRunCommand.run (/Users/steals/.local/share/sfdx/node_modules/salesforce-alm/dist/commands/force/apex/test/run.js:23:25)
    at ApexTestRunCommand._run (/Users/steals/.local/share/sfdx/node_modules/salesforce-alm/node_modules/@salesforce/command/lib/sfdxCommand.js:93:40)
    at Config.runCommand (/Users/steals/.local/share/sfdx/client/7.77.0-112dd7d412/node_modules/@oclif/config/lib/config.js:173:24)
    at Main.run (/Users/steals/.local/share/sfdx/client/7.77.0-112dd7d412/node_modules/@oclif/command/lib/main.js:27:9)
    at Main._run (/Users/steals/.local/share/sfdx/client/7.77.0-112dd7d412/node_modules/@oclif/command/lib/command.js:43:20)
    at Object.run (/Users/steals/.local/share/sfdx/client/7.77.0-112dd7d412/dist/cli.js:32:20)
Unhandled rejection TypeError: Cannot read property 'Id' of null
    at /Users/steals/.local/share/sfdx/node_modules/salesforce-alm/dist/lib/apex/apexTestApi.js:958:54
    at Array.forEach (<anonymous>)
    at /Users/steals/.local/share/sfdx/node_modules/salesforce-alm/dist/lib/apex/apexTestApi.js:957:21
    at processImmediate (internal/timers.js:456:21)
From previous event:
    at ApexTestApi.retrieveApexCodeCoverage (/Users/steals/.local/share/sfdx/node_modules/salesforce-alm/dist/lib/apex/apexTestApi.js:943:14)
    at /Users/steals/.local/share/sfdx/node_modules/salesforce-alm/dist/lib/apex/apexTestApi.js:843:29
From previous event:
    at ApexTestApi.retrieveAndStoreTestResults (/Users/steals/.local/share/sfdx/node_modules/salesforce-alm/dist/lib/apex/apexTestApi.js:841:14)
    at /Users/steals/.local/share/sfdx/node_modules/salesforce-alm/dist/lib/apex/apexTestApi.js:688:53
    at processImmediate (internal/timers.js:456:21)
From previous event:
    at /Users/steals/.local/share/sfdx/node_modules/salesforce-alm/dist/lib/apex/apexTestApi.js:688:37
    at processTicksAndRejections (internal/process/task_queues.js:97:5)

The same command against the same org but without --codecoverage parameter finished successfully. Also If I run test run with code coverage against scratch org it also finished without error.

Expected result

sfdx force:apex:test:run with --codecoverage flag should not throw any exceptions when runs against developer org with namespace

Additional information

sfdx-cli/7.77.0-112dd7d412 darwin-x64 node-v12.18.3

~/Workspaces ❯❯❯ sfdx plugins --core @oclif/plugin-autocomplete 0.2.0 @oclif/plugin-commands 1.3.0 (core) @oclif/plugin-not-found 1.2.4 (core) @oclif/plugin-plugins 1.9.1 (core) @oclif/plugin-warn-if-update-available 1.7.0 (core) @oclif/plugin-which 1.0.3 (core) @salesforce/lwc-dev-server 2.5.1 ├─ @oclif/plugin-update 1.3.9 └─ @oclif/plugin-help 2.2.1 @salesforce/sfdx-diff 0.0.6 @salesforce/sfdx-trust 3.4.3 (core) alias 1.1.2 (core) analytics 1.12.1 (core) auth 1.3.0 (core) config 1.1.9 (core) etcopydata 0.5.7 generator 1.1.3 (core) isvte-sfdx-plugin 1.1.7 salesforcedx 50.3.1 (50.3.1) ├─ apex 0.1.2 ├─ custom-metadata 1.0.10 ├─ @salesforce/sfdx-plugin-lwc-test 0.1.7 ├─ templates 50.1.0 └─ salesforce-alm 50.3.1 sfdx-cli 7.77.0 (core) sfdx-falcon 0.0.93 sfdx-git-packager 0.0.0 (link) /Users/steals/Work/sfdx-git-packager sfdx-migration-automatic 2.0.1 sfpowerkit 2.2.8 shane-sfdx-plugins 4.41.2 ├─ @mshanemc/plugin-streaming 1.1.7 └─ @mshanemc/sfdx-sosl 1.1.0

steals avatar Oct 27 '20 18:10 steals

Hi there,

I am having the same issue.

sfdx force:apex:test:run --tests ServiceTest --resultformat human --outputdir /salesforce/.sfdx/tools/testresults/apex --loglevel error --codecoverage

Getting:

Unhandled rejection TypeError: Cannot read property 'Id' of null at records.forEach.record (/usr/local/lib/node_modules/sfdx-cli/node_modules/salesforce-alm/dist/lib/apex/apexTestApi.js:958:54) at Array.forEach (<anonymous>) at org.retrieveMaxApiVersion.then.then.coverageResponse (/usr/local/lib/node_modules/sfdx-cli/node_modules/salesforce-alm/dist/lib/apex/apexTestApi.js:957:21) at tryCatcher (/usr/local/lib/node_modules/sfdx-cli/node_modules/bluebird/js/release/util.js:16:23) at Promise._settlePromiseFromHandler (/usr/local/lib/node_modules/sfdx-cli/node_modules/bluebird/js/release/promise.js:547:31) at Promise._settlePromise (/usr/local/lib/node_modules/sfdx-cli/node_modules/bluebird/js/release/promise.js:604:18) at Promise._settlePromise0 (/usr/local/lib/node_modules/sfdx-cli/node_modules/bluebird/js/release/promise.js:649:10) at Promise._settlePromises (/usr/local/lib/node_modules/sfdx-cli/node_modules/bluebird/js/release/promise.js:729:18) at _drainQueueStep (/usr/local/lib/node_modules/sfdx-cli/node_modules/bluebird/js/release/async.js:93:12) at _drainQueue (/usr/local/lib/node_modules/sfdx-cli/node_modules/bluebird/js/release/async.js:86:9) at Async._drainQueues (/usr/local/lib/node_modules/sfdx-cli/node_modules/bluebird/js/release/async.js:102:5) at Immediate.Async.drainQueues [as _onImmediate] (/usr/local/lib/node_modules/sfdx-cli/node_modules/bluebird/js/release/async.js:15:14) at runCallback (timers.js:705:18) at tryOnImmediate (timers.js:676:5) at processImmediate (timers.js:658:5) ERROR running force:apex:test:run: Cannot read property 'message' of undefined

My configuration:

@oclif/plugin-autocomplete 0.1.5 (core) @oclif/plugin-commands 1.3.0 (core) @oclif/plugin-help 3.2.0 (core) @oclif/plugin-not-found 1.2.4 (core) @oclif/plugin-plugins 1.9.1 (core) @oclif/plugin-update 1.3.10 (core) @oclif/plugin-warn-if-update-available 1.7.0 (core) @oclif/plugin-which 1.0.3 (core) @salesforce/sfdx-trust 3.6.0 (core) alias 1.1.2 (core) analytics 1.12.1 (core) auth 1.3.3 (core) config 1.1.10 (core) generator 1.1.3 (core) salesforcedx 50.3.1 (core) ├─ @salesforce/sfdx-plugin-lwc-test 0.1.7 (core) ├─ custom-metadata 1.0.10 (core) ├─ templates 50.1.0 (core) ├─ apex 0.1.2 (core) └─ salesforce-alm 50.3.1 (core) sfdx-cli 7.78.1 (core)

maximomrtnz avatar Nov 11 '20 00:11 maximomrtnz

I'm having the same issue as well, very similar error message.

myuser@mymachine MINGW64 ~/Documents/salesforce/develop (master) $ sfdx force:apex:test:run --codecoverage --testlevel RunSpecifiedTests --tests Test_ActionCDC_Handler.testCDC_Basic -u develop --resultformat json --outputdir ./apex_tests Unhandled rejection TypeError: Cannot read property 'Id' of null at C:\Users\myuser\AppData\Local\sfdx\client\7.81.0-7b953c80d1\node_modules\salesforce-alm\dist\lib\apex\apexTestApi.js:958:54
at Array.forEach () at C:\Users\myuser\AppData\Local\sfdx\client\7.81.0-7b953c80d1\node_modules\salesforce-alm\dist\lib\apex\apexTestApi.js:957:21
at tryCatcher (C:\Users\myuser\AppData\Local\sfdx\client\7.81.0-7b953c80d1\node_modules\bluebird\js\release\util.js:16:23)
at Promise._settlePromiseFromHandler (C:\Users\myuser\AppData\Local\sfdx\client\7.81.0-7b953c80d1\node_modules\bluebird\js\release\promise.js:547:31) at Promise._settlePromise (C:\Users\myuser\AppData\Local\sfdx\client\7.81.0-7b953c80d1\node_modules\bluebird\js\release\promise.js:604:18) at Promise._settlePromise0 (C:\Users\myuser\AppData\Local\sfdx\client\7.81.0-7b953c80d1\node_modules\bluebird\js\release\promise.js:649:10) at Promise._settlePromises (C:\Users\myuser\AppData\Local\sfdx\client\7.81.0-7b953c80d1\node_modules\bluebird\js\release\promise.js:729:18) at _drainQueueStep (C:\Users\myuser\AppData\Local\sfdx\client\7.81.0-7b953c80d1\node_modules\bluebird\js\release\async.js:93:12) at _drainQueue (C:\Users\myuser\AppData\Local\sfdx\client\7.81.0-7b953c80d1\node_modules\bluebird\js\release\async.js:86:9)
at Async._drainQueues (C:\Users\myuser\AppData\Local\sfdx\client\7.81.0-7b953c80d1\node_modules\bluebird\js\release\async.js:102:5) at Immediate.Async.drainQueues [as _onImmediate] (C:\Users\myuser\AppData\Local\sfdx\client\7.81.0-7b953c80d1\node_modules\bluebird\js\release\async.js:15:14) at processImmediate (internal/timers.js:456:21)

{ "status": 1, "name": "TypeError", "message": "Cannot read property 'message' of undefined", "exitCode": 1, "commandName": "ApexTestRunCommand", "stack": "TypeError: Cannot read property 'message' of undefined\n at C:\\Users\\myuser\\AppData\\Local\\sfdx\\client\\7.81.0-7b953c80d1\\node_modules\\salesforce-alm\\dist\\lib\\apex\\apexTestApi.js:534:65\n at tryCatcher (C:\\Users\\myuser\\AppData\\Local\\sfdx\\client\\7.81.0-7b953c80d1\\node_modules\\bluebird\\js\\release\\util.js:16:23)\n at Promise._settlePromiseFromHandler (C:\\Users\\myuser\\AppData\\Local\\sfdx\\client\\7.81.0-7b953c80d1\\node_modules\\bluebird\\js\\release\\promise.js:547:31)\n at Promise._settlePromise (C:\\Users\\myuser\\AppData\\Local\\sfdx\\client\\7.81.0-7b953c80d1\\node_modules\\bluebird\\js\\release\\promise.js:604:18)\n at Promise._settlePromise0 (C:\\Users\\myuser\\AppData\\Local\\sfdx\\client\\7.81.0-7b953c80d1\\node_modules\\bluebird\\js\\release\\promise.js:649:10)\n at Promise._settlePromises (C:\\Users\\myuser\\AppData\\Local\\sfdx\\client\\7.81.0-7b953c80d1\\node_modules\\bluebird\\js\\release\\promise.js:725:18)\n at _drainQueueStep (C:\\Users\\myuser\\AppData\\Local\\sfdx\\client\\7.81.0-7b953c80d1\\node_modules\\bluebird\\js\\release\\async.js:93:12)\n at _drainQueue (C:\\Users\\myuser\\AppData\\Local\\sfdx\\client\\7.81.0-7b953c80d1\\node_modules\\bluebird\\js\\release\\async.js:86:9)\n at Async._drainQueues (C:\\Users\\myuser\\AppData\\Local\\sfdx\\client\\7.81.0-7b953c80d1\\node_modules\\bluebird\\js\\release\\async.js:102:5)\n at Immediate.Async.drainQueues [as _onImmediate] (C:\\Users\\myuser\\AppData\\Local\\sfdx\\client\\7.81.0-7b953c80d1\\node_modules\\bluebird\\js\\release\\async.js:15:14)\n at processImmediate (internal/timers.js:456:21)\nOuter stack:\n at Function.wrap (C:\\Users\\myuser\\AppData\\Local\\sfdx\\client\\7.81.0-7b953c80d1\\node_modules\\salesforce-alm\\node_modules\\@salesforce\\core\\lib\\sfdxError.js:171:27)\n at ApexTestRunCommand.catch (C:\\Users\\myuser\\AppData\\Local\\sfdx\\client\\7.81.0-7b953c80d1\\node_modules\\salesforce-alm\\dist\\ToolbeltCommand.js:248:46)\n at async ApexTestRunCommand._run (C:\\Users\\myuser\\AppData\\Local\\sfdx\\client\\7.81.0-7b953c80d1\\node_modules\\@salesforce\\command\\lib\\sfdxCommand.js:97:13)\n at async Config.runCommand (C:\\Users\\myuser\\AppData\\Local\\sfdx\\client\\7.81.0-7b953c80d1\\node_modules\\@oclif\\config\\lib\\config.js:173:24)\n at async Main.run (C:\\Users\\myuser\\AppData\\Local\\sfdx\\client\\7.81.0-7b953c80d1\\node_modules\\@oclif\\command\\lib\\main.js:27:9)\n at async Main._run (C:\\Users\\myuser\\AppData\\Local\\sfdx\\client\\7.81.0-7b953c80d1\\node_modules\\@oclif\\command\\lib\\command.js:43:20)\n at async Object.run (C:\\Users\\myuser\\AppData\\Local\\sfdx\\client\\7.81.0-7b953c80d1\\dist\\cli.js:32:20)", "warnings": [] }

troveryor avatar Nov 20 '20 16:11 troveryor

Any update on this issue? Having similar now

sfdx force:apex:test:run -u ST -w 600 -r junit --codecoverage --testlevel RunLocalTests --synchronous -d testResults Unhandled rejection ERROR_HTTP_414: <h1>Bad Message 414</h1><pre>reason: URI Too Long</pre> at HttpApi.getError (/opt/hostedtoolcache/node/10.23.1/x64/lib/node_modules/sfdx-cli/node_modules/jsforce/lib/http-api.js:250:13) at /opt/hostedtoolcache/node/10.23.1/x64/lib/node_modules/sfdx-cli/node_modules/jsforce/lib/http-api.js:95:22 at tryCallOne (/opt/hostedtoolcache/node/10.23.1/x64/lib/node_modules/sfdx-cli/node_modules/promise/lib/core.js:37:12) at /opt/hostedtoolcache/node/10.23.1/x64/lib/node_modules/sfdx-cli/node_modules/promise/lib/core.js:123:15 at flush (/opt/hostedtoolcache/node/10.23.1/x64/lib/node_modules/sfdx-cli/node_modules/asap/raw.js:50:29) at process._tickCallback (internal/process/next_tick.js:61:11) ERROR running force:apex:test:run: Cannot read property 'message' of undefined ERROR running force:apex:test:coverage:format: ENOENT: no such file or directory, open './testResults/test-result-codecoverage.json' total 4

davidbrowaeys avatar Jan 12 '21 20:01 davidbrowaeys

We have determined that the issue you reported exists in code owned by another team that uses only the official support channels. To ensure that your issue is addressed, open an official Salesforce customer support ticket with a link to this issue. We encourage anyone experiencing this issue to do the same to increase the priority. We will keep this issue open for the community to collaborate on.

github-actions[bot] avatar Sep 22 '23 16:09 github-actions[bot]