shopify-script-creator icon indicating copy to clipboard operation
shopify-script-creator copied to clipboard

Fix for `undefined method 'map' for nil`

Open ewan-jrpets opened this issue 2 years ago • 1 comments

Hi, thanks for this awesome project!

I found a slight issue which caused a runtime error. We used the script creator to do a 'free gift over £x' deal, and ran into a slight but that happened seemly at random. Using Shopify's debug tools did not show any rhyme or reason for what could be causing it.

This PR is just a patch to return false instead of causing the script to panic.

ewan-jrpets avatar Oct 31 '22 15:10 ewan-jrpets

Hello, thanks for the PR! That is very strange, I wouldn't expect that to ever happen. The change would need to be here instead as the changed file is generated based on that. There's some information about how that works here.

However, I think since if this can happen here, it would be better to change this to guard all the qualifiers and do something like:

cart.line_items.send(@li_match_type) do |item|
  next false if item.nil?
  qualifier.match?(item)
end

jgodson avatar Nov 09 '22 13:11 jgodson

Hi, sorry for the delay and thanks for the feedback, I've done the changes. It generated the script with the correct fix, but I have not been able to test it in production just yet. It seems to work when testing in a dev shop.

ewan-jrpets avatar Dec 05 '22 11:12 ewan-jrpets

I tested this and it doesn't cause any issues with my test scripts, I've never hit the nil line item but this should take care of that. It will have an effect on the all items matching case since we're returning false, but I think that's probably fine since an error would have also caused the script not to work anyway. Going to merge it in. Thanks!

jgodson avatar Jan 29 '23 15:01 jgodson