Whats the best way to check if a var from a previous step exists before referencing it?

This topic was automatically generated from Slack. You can find the original thread here.

Nick G : Whats the best way to check if a var from a previous step exists before referencing it? I am trying

 if (typeof steps.shopify_update_inv.product.sku !== 'undefined') {//do something with the var } else {//do something else}

This is returning type errors occasionally. In my previous step I am awaiting two values but it doesnt seem to wait for both in all cases

this.product = await shopify.inventoryItem.get(params.product_id);
this.resp_inv = await shopify.inventoryLevel.set(shopify_params);

Would appreciate any direction here, thanks!

Dylan Sather (Pipedream) : if you’re seeing TypeErrors, it’s likely that some intermediate property (like steps.shopify_update_inv.product) is undefined, which means you won’t be able to read the sku property.

There are a few solutions to this problem, but Lodash’s get function will handle the absence of intermediate object properties and return undefined if the value doesn’t exist: Handle missing variable - Pipedream

Dylan Sather (Pipedream) : do you know if the Shopify methods like shopify.inventoryItem.get return Promises? As long as you’re awaiting those, Pipedream should wait for them to resolve before the next step runs, but feel free to add console.log statements at the end of the step to confirm

Nick G : Ahh since i am checking for the property sku typeof undefined throws an error, I might try using hasOwnProperty in my if

Nick G : It should return promises GitHub - MONEI/Shopify-api-node: Official Node Shopify connector sponsored by MONEI.net

Dylan Sather (Pipedream) : Do you see the step exports below the Shopify update step for these failed events? That should make it clear what’s returned and what’s not from the step

Nick G : Because of the quantity of events they no longer appear in my workflow list to be retried - is there a way to trigger that from the error workflow?

Nick G : Which has made it challenging to debug

Dylan Sather (Pipedream) : Not currently, but you can fetch the last 100 errors using the REST API, which should contain the original payload, so you can send it to the workflow: https://docs.pipedream.com/api/rest/#get-workflow-errors .

We’re planning to expose this in the UI eventually so you get a list of the last 100 errors for each workflow (regardless of how many successful events are processed).

Nick G : ok I was able to grab the original event body from the error and manually edit the test event from my workflow and rerun it, it succeeded without issue. Going to try logging more details and review throughout the day