commerce-sdk-isomorphic icon indicating copy to clipboard operation
commerce-sdk-isomorphic copied to clipboard

object is not iterable (cannot read property Symbol(Symbol.iterator))

Open janderson-watchbox opened this issue 11 months ago • 2 comments

u.searchParams & h.searchParams may be null and causes a TypeError -- and noisy error in Sentry

File: commerce-sdk-isomorphic/lib/index.esm.js

Source functions: loginGuestUser: function (e, t) {return vI.apply(this, arguments);}, loginRegisteredUserB2C: function (e, t, r) {return mI.apply(this, arguments);},

Line with error: if (((d = e.sent), (c = (null === (i = d.headers) || void 0 === i ? void 0 : i.get("location")) || d.url), (u = new URL(c)), (l = Object.fromEntries(u.searchParams.entries())), !(d.status >= 400 || l.error))) { Line with error: if (((u = e.sent), (l = (null === (i = u.headers) || void 0 === i ? void 0 : i.get("location")) || u.url), (h = new URL(l)), (f = Object.fromEntries(h.searchParams.entries())), !(u.status >= 400 || f.error))) {

Suggested change: u.searchParams.entries to u.searchParams?.entries ?? {} and same for h.searchParams

janderson-watchbox avatar Dec 20 '24 19:12 janderson-watchbox

Hey @janderson-watchbox, thanks for creating this issue. Wanted to check something, have you confirmed that u.searchParams.entries() is null or is it an object? Asking as I tested passing around different inputs to Object.fromEntries() and this is what I found:

Object.fromEntries(undefined)

VM418:1 Uncaught TypeError: undefined is not iterable
    at Function.fromEntries (<anonymous>)
    at <anonymous>:1:8

Object.fromEntries(null)

VM433:1 Uncaught TypeError: undefined is not iterable
    at Function.fromEntries (<anonymous>)
    at <anonymous>:1:8

Object.fromEntries({})

VM448:1 Uncaught TypeError: object is not iterable (cannot read property Symbol(Symbol.iterator))
    at Function.fromEntries (<anonymous>)
    at <anonymous>:1:8

Seems like an object is getting passed to the function Object.fromEntries() which is also unexpected, I'll create a ticket in the backlog to investigate

joeluong-sfcc avatar Feb 03 '25 19:02 joeluong-sfcc

This issue has been linked to a new work item: W-17766483

git2gus[bot] avatar Feb 06 '25 14:02 git2gus[bot]