OpenFn / grassroot-soccer

Grassroot Soccer CommCare-Salesforce integrations
https://openfn.github.io/grassroot-soccer/
0 stars 0 forks source link

TypeError on split function in Upsert Risk & Vulnerability Assessment | Service Referral #33

Closed daissatou2 closed 2 years ago

daissatou2 commented 2 years ago

Describe the bug

I am seeing the error "TypeError [Error]: Cannot read property 'split' of undefined" for Upsert Risk & Vulnerability Assessment | Service Referral. We are calling the split function on several fields. Is there an easy way to determine which field(s) is causing this error without having to check each field? Maybe an update to the logs?

To Reproduce

  1. Here is a link to a failed run on OpenFn.org wihch is indicative of the bug: https://www.openfn.org/projects/pd3yk4/runs/06177051-bcea-72bb-b331-67168f06926b

expression.js

Link to the job itself in Github: https://github.com/OpenFn/grassroot-soccer/blob/master/jobs/upsertRiskVulnerabilityNewReferrals.js

state.json

Salesforce: GRS Salesforce Production https://www.openfn.org/projects/pd3yk4/messages/06177051-a47e-731c-82de-e882d34bacd5

To test/resolve

  1. After the desired output is working locally (from the CLI), please [push commits to master || open a pull request].
  2. [Please test the change on OpenFn.org by re-running this run (https://www.openfn.org/projects/pd3yk4/runs/06177051-bcea-72bb-b331-67168f06926b) and confirming success.]
lakhassane commented 2 years ago

@daissatou2 unfortunately there is no other way and the logs are auto-generated so we got no hands in it.

One typical way is to defined our own split method somewhere and use it instead of the built-in string split method

aleksa-krolls commented 2 years ago

@lakhassane @daissatou2 I recommend you two get on a call to (1) determine the exact cause of the error here, (2) consider where in the job we need to handle for undefined values, and (3) discuss general troubleshooting UX/ if there's anything we can do in logging to help.

lakhassane commented 2 years ago

With a quick check I can see there is not a risk_assessment object in the message. So it's likely that L227 can potentially trigger this error.

lakhassane commented 2 years ago

@daissatou2 I find out the reason. It was still risk_assessment being undefined. However this issue is also related to upsertIf that evaluates the mapping before even checking if it should upsert or not (with the if).

I made a correction with the custom split we discuss so the job does not fail but I will also update salesforce to prevent this for next time. Find the run here: https://www.openfn.org/projects/pd3yk4/runs/06178336-9acf-7d3e-8792-3ff4551d586c