Skip to content

Inexplicable error when using reduce on an object #1033

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

Closed
bioball opened this issue Mar 9, 2015 · 5 comments
Closed

Inexplicable error when using reduce on an object #1033

bioball opened this issue Mar 9, 2015 · 5 comments
Labels

Comments

@bioball
Copy link

bioball commented Mar 9, 2015

I run a production site where I capture all client-side exceptions on my server. Currently, I'm trying to debug this error that I can't explain, nor reproduce, so I'm hoping that you guys would have some clue...

I'm doing a reduce operation on an object that looks like this:

{
  "4": {
    "quantity": 0,
    "id": 4
  },
  "13": {
    "quantity": 0,
    "id": 13
  },
  "17": {
    "quantity": 0,
    "id": 17
  },
  "18": {
    "quantity": 0,
    "id": 18
  },
  "20": {
    "quantity": 0,
    "id": 20
  },
  "22": {
    "quantity": 0,
    "id": 22
  },
  "23": {
    "quantity": 0,
    "id": 23
  },
  "36": {
    "quantity": 0,
    "id": 36
  },
  "37": {
    "quantity": 0,
    "id": 37
  }
}

Basically, it's a hash of line-items, and I reduce it to get the total number of items. Here's my code, copy and pasted.

_.reduce(items, function(sum, product){
  return sum + product.quantity;
}, 0);

And results in this kind of error message: Cannot read property "quantity" of undefined.

This error only appears on iPhone Safari, it seems, just by inspecting the browser useragent. Here's the some of the useragents that errored:

  • Mozilla/5.0 (iPhone; CPU iPhone OS 8_1_2 like Mac OS X) AppleWebKit/600.1.4 (KHTML, like Gecko) GSA/5.2.43972 Mobile/12B440 Safari/600.1.4
  • Mozilla/5.0 (iPad; CPU OS 8_1_3 like Mac OS X) AppleWebKit/600.1.4 (KHTML, like Gecko) Version/8.0 Mobile/12B466 Safari/600.1.4

I can't reproduce this on my own iPhone. Any idea what's is going on? Maybe because my keys can be parsed as ints, the object gets false interpreted as an Array?

This is on lodash 2.4

@jdalton
Copy link
Member

jdalton commented Mar 9, 2015

iOS has had some JIT bugs pop up that affect lodash pre 3.0 and Underscore.
Can you try with lodash v3.5.0 and report back?

@bioball
Copy link
Author

bioball commented Mar 9, 2015

Ok. That most likely is it. Couldn't find anything via Google related to this issue, so I should work on my Google-fu. I'll close this for now, and will re-open if this issue still comes up.

@bioball bioball closed this as completed Mar 9, 2015
@jdalton jdalton added the invalid label Mar 9, 2015
@bioball
Copy link
Author

bioball commented Mar 13, 2015

Just to put this to rest, this error has disappeared entirely since upping my version.

@jdalton
Copy link
Member

jdalton commented Mar 13, 2015

Nice!

@lock
Copy link

lock bot commented Jan 20, 2019

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked as resolved and limited conversation to collaborators Jan 20, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Development

No branches or pull requests

2 participants