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

Getting errors if any unit test fails with force:apex:test:run #210

Closed
paferpo opened this issue Oct 26, 2019 · 16 comments
Closed

Getting errors if any unit test fails with force:apex:test:run #210

paferpo opened this issue Oct 26, 2019 · 16 comments
Assignees
Labels
area:apex Highlights the apex functional area of the CLI. owned by another team The Salesforce CLI team does not own this work but will pass on the information to the correct team.

Comments

@paferpo
Copy link

paferpo commented Oct 26, 2019

Summary

Getting errors if a unit test fails after execution of the command force:apex:test:run:

Unhandled rejection TypeError: packageDirs is not iterable
ERROR running force:apex:test:run: Cannot read property 'message' of undefined

Looks like this is always happening when any unit test fails, not just with some specific test classes.

Steps To Reproduce:

  1. sfdx force:apex:test:run -n BatchDeletionServiceTest,CreationServiceTest -u username --codecoverage -w 60 -r human -d test-reports --verbose

Expected result

Test report output should not throw any error.

Actual result

The output is okay except the Failures section. If there any unit test failure, for instance:

CreationServiceTest.doNotLinkToExistingUserWithSameEmail Fail System.DmlException: SObjectFactory Create failed. State: {"Count":"1","Template":null,"SObjectType":"crm_EmailVerification__c"}, Cause: Insert failed. First exception on row 0; first error: CANNOT_EXECUTE_FLOW_TRIGGER, We can't save this record because the “EmailVerificationProcessing� process failed. Give your Salesforce admin these details. An unhandled fault has occurred in this flow
An unhandled fault has occurred while processing the flow. Please contact your system administrator for more information.: [] 798 Class.SObjectFactory.create: line 126, column 1 Class.SObjectBuilder.create: line 131, column 1 Class.TestDataFactory.createEmailVerification: line 66, column 1

Then, this is what the last part of the output looks like:

=== Failures
Unhandled rejection TypeError: packageDirs is not iterable
at ApexHumanReporter._findFile (C:\Program Files\Salesforce CLI\client\node_modules\salesforce-alm\dist\lib\test\reporter.js:235:34)
at stacks.forEach.stack (C:\Program Files\Salesforce CLI\client\node_modules\salesforce-alm\dist\lib\test\reporter.js:209:59)
at Array.forEach ()
at Object.format (C:\Program Files\Salesforce CLI\client\node_modules\salesforce-alm\dist\lib\test\reporter.js:204:36)
at Object.get (C:\Program Files\Salesforce CLI\client\node_modules\salesforce-alm\node_modules\heroku-cli-util\lib\table.js:59:19)
at render (C:\Program Files\Salesforce CLI\client\node_modules\salesforce-alm\node_modules\heroku-cli-util\lib\table.js:89:24)
at Proxy.table (C:\Program Files\Salesforce CLI\client\node_modules\salesforce-alm\node_modules\heroku-cli-util\lib\table.js:128:3)
at Logger.table (C:\Program Files\Salesforce CLI\client\node_modules\salesforce-alm\dist\lib\core\logApi.js:532:20)
at ApexHumanReporter.logTable (C:\Program Files\Salesforce CLI\client\node_modules\salesforce-alm\dist\lib\test\reporter.js:80:21)
at ApexHumanReporter.logFailuresTable (C:\Program Files\Salesforce CLI\client\node_modules\salesforce-alm\dist\lib\test\reporter.js:195:18)
at ApexHumanReporter.logTables (C:\Program Files\Salesforce CLI\client\node_modules\salesforce-alm\dist\lib\test\reporter.js:247:14)
at ApexHumanReporter.onFinished (C:\Program Files\Salesforce CLI\client\node_modules\salesforce-alm\dist\lib\test\reporter.js:251:14)
at ApexHumanReporter.onFinished (C:\Program Files\Salesforce CLI\client\node_modules\salesforce-alm\dist\lib\apex\apexTestApi.js:94:22)
at ApexHumanReporter.emit (C:\Program Files\Salesforce CLI\client\node_modules\salesforce-alm\dist\lib\test\reporter.js:136:34)
at org.getConfig.then.then.then.then.then.then.then (C:\Program Files\Salesforce CLI\client\node_modules\salesforce-alm\dist\lib\apex\apexTestApi.js:809:38)
at tryCatcher (C:\Program Files\Salesforce CLI\client\node_modules\salesforce-alm\node_modules\bluebird\js\release\util.js:16:23)
ERROR running force:apex:test:run: Cannot read property 'message' of undefined

Additional information

SFDX CLI Version(to find the version of the CLI engine run sfdx --version):
sfdx-cli/7.28.7 win32-x64 node-v10.15.3

SFDX plugin Version(to find the version of the CLI plugin run sfdx plugins --core)

@oclif/plugin-commands 1.2.3 (core)
@oclif/plugin-help 2.2.1 (core)
@oclif/plugin-not-found 1.2.3 (core)
@oclif/plugin-plugins 1.7.8 (core)
@oclif/plugin-update 1.3.9 (core)
@oclif/plugin-warn-if-update-available 1.7.0 (core)
@oclif/plugin-which 1.0.3 (core)
@salesforce/sfdx-trust 3.0.5 (core)
analytics 1.2.1 (core)
apexlink 0.4.2
gearset-sfdx-plugins 0.5.0
generator 1.1.1 (core)
salesforcedx 47.1.5 (core)
├─ force-language-services 47.5.0 (core)
└─ salesforce-alm 47.4.0 (core)

sfdx-cli 7.28.7 (core)

OS and version: Windows 10 Enterprise version 1903 (OS Build 18362.418)

@paferpo paferpo changed the title Getting errors if a unit test fails with force:apex:test:run Getting errors if any unit test fails with force:apex:test:run Oct 26, 2019
@clairebianchi
Copy link
Collaborator

@ntotten can you please take a look at this issue

@clairebianchi clairebianchi added the owned by another team The Salesforce CLI team does not own this work but will pass on the information to the correct team. label Oct 29, 2019
@paferpo
Copy link
Author

paferpo commented Jan 31, 2020

Hi, is there any way to track the status of this issue?
Thanks!

@PseudoDarwinist
Copy link

Hi ,
Is this issue resolved? I am trying to do the same thing and i am trying to run the apex tests through Jenkins and i get the same error.

  • sfdx force:apex:test:run -c -u ******** -r human -w 45
    Unhandled rejection TypeError: packageDirs is not iterable
    at ApexHumanReporter._findFile (/usr/local/lib/sfdx/node_modules/salesforce-alm/dist/lib/test/reporter.js:235:34)
    at stacks.forEach.stack (/usr/local/lib/sfdx/node_modules/salesforce-alm/dist/lib/test/reporter.js:209:59)
    at Array.forEach ()
    at Object.format (/usr/local/lib/sfdx/node_modules/salesforce-alm/dist/lib/test/reporter.js:204:36)
    at Object.get (/usr/local/lib/sfdx/node_modules/salesforce-alm/node_modules/heroku-cli-util/lib/table.js:59:19)
    at render (/usr/local/lib/sfdx/node_modules/salesforce-alm/node_modules/heroku-cli-util/lib/table.js:89:24)
    at Proxy.table (/usr/local/lib/sfdx/node_modules/salesforce-alm/node_modules/heroku-cli-util/lib/table.js:128:3)
    at Logger.table (/usr/local/lib/sfdx/node_modules/salesforce-alm/dist/lib/core/logApi.js:532:20)
    at ApexHumanReporter.logTable (/usr/local/lib/sfdx/node_modules/salesforce-alm/dist/lib/test/reporter.js:80:21)
    at ApexHumanReporter.logFailuresTable (/usr/local/lib/sfdx/node_modules/salesforce-alm/dist/lib/test/reporter.js:195:18)
    at ApexHumanReporter.logTables (/usr/local/lib/sfdx/node_modules/salesforce-alm/dist/lib/test/reporter.js:247:14)
    at ApexHumanReporter.onFinished (/usr/local/lib/sfdx/node_modules/salesforce-alm/dist/lib/test/reporter.js:251:14)
    at ApexHumanReporter.onFinished (/usr/local/lib/sfdx/node_modules/salesforce-alm/dist/lib/apex/apexTestApi.js:94:22)
    at ApexHumanReporter.emit (/usr/local/lib/sfdx/node_modules/salesforce-alm/dist/lib/test/reporter.js:136:34)
    at org.getConfig.then.then.then.then.then.then.then (/usr/local/lib/sfdx/node_modules/salesforce-alm/dist/lib/apex/apexTestApi.js:809:38)
    at tryCatcher (/usr/local/lib/sfdx/node_modules/salesforce-alm/node_modules/bluebird/js/release/util.js:16:23)
    ERROR running force:apex:test:run: Cannot read property 'message' of undefined

@lcampos
Copy link

lcampos commented Feb 20, 2020

Looking at the stack trace the problem seems to be related to an issue with the data returned from the server being incomplete when we format it before we print the result. We recently made some updates to that area so I would need to know which versions of the plugins & CLI you are running.

@paferpo @PseudoDarwinist can you let me know which version of the CLI you're currently on and which plugins you are running (sfdx plugins --core) ?

@lcampos lcampos self-assigned this Feb 20, 2020
@lcampos lcampos added the more information required Issue requires more information or a response from the customer label Feb 20, 2020
@paferpo
Copy link
Author

paferpo commented Feb 24, 2020

Hi @lcampos I have just tested and still get the same errors, to test it, I have just made an assert to fail to reproduce it and got the same (Unhandled rejection TypeError: packageDirs is not iterable).

This is the version I'm using:

sfdx-cli/7.47.0 win32-x64 node-v10.15.0
@oclif/plugin-autocomplete 0.1.5 (core)
@oclif/plugin-commands 1.2.3 (core)
@oclif/plugin-help 2.2.1 (core)
@oclif/plugin-not-found 1.2.3 (core)
@oclif/plugin-plugins 1.7.8 (core)
@oclif/plugin-update 1.3.9 (core)
@oclif/plugin-warn-if-update-available 1.7.0 (core)
@oclif/plugin-which 1.0.3 (core)
@salesforce/sfdx-trust 3.0.5 (core)
analytics 1.7.1 (core)
generator 1.1.1 (core)
salesforcedx 48.2.0 (core)
├─ salesforcedx-templates 48.3.0 (core)
├─ @salesforce/sfdx-plugin-lwc-test 0.1.5 (core)
└─ salesforce-alm 48.3.0 (core)

sfdx-cli 7.47.0 (core)

This is confusing for developers because Bamboo shows these errors in the build results page and they think it's a problem with sfdx and not with their changes:

image

@no-response no-response bot removed the more information required Issue requires more information or a response from the customer label Feb 24, 2020
@PseudoDarwinist
Copy link

I am still receiving the error .The cli version that i am using is(by running sfdx --version) : sfdx-cli/7.44.0-e77f9c8515 linux-x64 node-v10.15.3

@lcampos
Copy link

lcampos commented Feb 26, 2020

@paferpo @PseudoDarwinist we're looking into this and will update this thread once we have a fix for it.
cc @smaddox-sf

@gatormike
Copy link

@lcampos Any update on this? I'm currently getting with sfdx-cli/7.59.0-05e06e37e0 win32-x64 node-v10.15.3
Thank you!

@lcampos
Copy link

lcampos commented Jun 5, 2020

Hi @gatormike, as you might've already experienced the apex commands in general have a few issues like this one. We've taken a step back and are currently working on making the apex commands reliable. This means this and the rest of the issues are being considered and addressed. The changes will start getting to you in the next weeks and I'll make sure to update this and the rest of the issues we address.

cc @smaddox-sf

@kvan
Copy link

kvan commented Sep 17, 2020

@lcampos FYI I started experiencing this in the last couple of weeks, I was not seeing it a month-ish ago. It appears to be org agnostic once it starts happening.

sfdx-cli/7.74.1-32db2396ed win32-x64 node-v12.18.3
salesforcedx 49.10.0 (core)
├─ templates 49.4.4 (core)
├─ custom-metadata 1.0.10 (core)
├─ apex 0.0.9 (core)
├─ @salesforce/sfdx-plugin-lwc-test 0.1.7 (core)
└─ salesforce-alm 49.11.0 (core)

@andreyzh
Copy link

Getting the same thing now with 7.74 as well running
PS C:\Users\conazh> sfdx force:apex:test:report -i 707690000AgKh***** --resultformat human > C:\Users\conazh\Desktop\PRO D-Test-Result.txt -u *****

@steals
Copy link

steals commented Sep 22, 2020

@lcampos Algo getting a similar error:

sfdx force:apex:test:run --resultformat junit --codecoverage --testlevel RunLocalTests --wait 10
Unhandled rejection TypeError: Cannot read property 'Id' of null
    at /Users/steals/.local/share/sfdx/node_modules/salesforce-alm/dist/lib/apex/apexTestApi.js:957:54
    at Array.forEach (<anonymous>)
    at /Users/steals/.local/share/sfdx/node_modules/salesforce-alm/dist/lib/apex/apexTestApi.js:956:21
    at tryCatcher (/Users/steals/.local/share/sfdx/node_modules/salesforce-alm/node_modules/bluebird/js/release/util.js:16:23)
    at Promise._settlePromiseFromHandler (/Users/steals/.local/share/sfdx/node_modules/salesforce-alm/node_modules/bluebird/js/release/promise.js:547:31)
    at Promise._settlePromise (/Users/steals/.local/share/sfdx/node_modules/salesforce-alm/node_modules/bluebird/js/release/promise.js:604:18)
    at Promise._settlePromise0 (/Users/steals/.local/share/sfdx/node_modules/salesforce-alm/node_modules/bluebird/js/release/promise.js:649:10)
    at Promise._settlePromises (/Users/steals/.local/share/sfdx/node_modules/salesforce-alm/node_modules/bluebird/js/release/promise.js:729:18)
    at _drainQueueStep (/Users/steals/.local/share/sfdx/node_modules/salesforce-alm/node_modules/bluebird/js/release/async.js:93:12)
    at _drainQueue (/Users/steals/.local/share/sfdx/node_modules/salesforce-alm/node_modules/bluebird/js/release/async.js:86:9)
    at Async._drainQueues (/Users/steals/.local/share/sfdx/node_modules/salesforce-alm/node_modules/bluebird/js/release/async.js:102:5)
    at Immediate.Async.drainQueues [as _onImmediate] (/Users/steals/.local/share/sfdx/node_modules/salesforce-alm/node_modules/bluebird/js/release/async.js:15:14)
    at processImmediate (internal/timers.js:456:21)

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

The strange thing is that all tests passed successfully and I don't get this error when I run the same command against scratch org with the same codebase. This error occurs only with a packaging org (regular developer org with a namespace)

SFDX CLI Version sfdx-cli/7.74.1-32db2396ed darwin-x64 node-v12.18.3
SFDX Plugins

@oclif/plugin-autocomplete 0.2.0
@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
etcopydata 0.5.7
isvte-sfdx-plugin 1.1.6
salesforce-alm 49.11.0
sfdx-falcon 0.0.93
sfdx-migration-automatic 2.0.1
sfpowerkit 2.1.6
shane-sfdx-plugins 4.39.2

or

SFDX CLI Version sfdx-cli/7.74.1-32db2396ed linux-x64 node-v12.18.3 without any plugins

@maximomrtnz
Copy link

Hi there,

I am facing the same issue:

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

SFDX CLI Version:

@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) ├─ apex 0.1.2 (core) ├─ custom-metadata 1.0.10 (core) ├─ templates 50.1.0 (core) └─ salesforce-alm 50.3.1 (core) sfdx-cli 7.78.1 (core)

@nvuillam
Copy link

Same here.

@movsar
Copy link

movsar commented Mar 12, 2021

Same

@preddivari preddivari added the area:apex Highlights the apex functional area of the CLI. label Sep 21, 2023
@mshanemc
Copy link
Contributor

mshanemc commented Oct 4, 2023

I ran this with force:apex:test:run

  1. all passing tests
  2. one failing test

Was not able to reproduce the error. salesforce-alm is gone, so it there's still a way to get this error, please open new issue

@mshanemc mshanemc closed this as completed Oct 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:apex Highlights the apex functional area of the CLI. owned by another team The Salesforce CLI team does not own this work but will pass on the information to the correct team.
Projects
None yet
Development

No branches or pull requests