Skip to content
This repository has been archived by the owner on Jan 9, 2024. It is now read-only.

TypeError: filterWrapper is not iterable #206

Closed
nukeop opened this issue Jul 26, 2023 · 22 comments
Closed

TypeError: filterWrapper is not iterable #206

nukeop opened this issue Jul 26, 2023 · 22 comments
Labels

Comments

@nukeop
Copy link

nukeop commented Jul 26, 2023

Started occurring on pretty much every search. The error is thrown in ytsr/lub/utils:23, called by the getFilters function.

@nukeop
Copy link
Author

nukeop commented Jul 26, 2023

On further debugging, it looks like wrapper.subMenu.searchSubMenuRenderer doesn't have the groups attribute sometimes.

@sdasda7777
Copy link

Yeah, I keep getting this error, while it doesn't seem to really appear at all for other users. Could the search be blocked outside the US, perhaps?

@rfcrocha
Copy link

rfcrocha commented Jul 27, 2023

I'm trying ytsr for the first time and finding the same issue
EDIT - seems it is random. It ended up working for a couple of times and failed again after

@nukeop
Copy link
Author

nukeop commented Jul 27, 2023

I mitigated it somewhat simply by applying exponential backoff with 3 retries. There are still times when it fails though.

@athammer
Copy link

might be the same issue here. You might want to go into the node_modules of your project and manually change it till the owner can put in a fix

#180

@Zer0ne83
Copy link

As above, C is not iterable at i.parseFilters... Approx 1/30 requests actually work/return results. Time/delay between requests (including 24 hours+) makes no difference. I am also outside US (ref @sdasda7777's question). Will update if using US localized IP solves the issue.

@noviardi1986
Copy link

I think the issue is nothing to do with ytsr, it is rejected by youtube. And returned nothing.

@SeiRann
Copy link

SeiRann commented Aug 2, 2023

i have run the filterWrapper code thru chatgpt and it give a safety check for the filterWrapper which seems to fix the issue
const filterWrapper = ((wrapper.subMenu || wrapper.submenu)?.searchSubMenuRenderer || {}).groups || [];
here's the full explanation:
The code you provided seems to be a JavaScript module that exports a function parseFilters(json) to parse and extract filter information from a JSON object. The function appears to be used in a search-related context, possibly to parse YouTube search results.

As for non-iterable errors, this code should not produce any non-iterable errors on its own. It seems to be using various iterators like for...of loops to traverse arrays and objects, which are appropriate methods for iterating over iterable data structures in JavaScript.

However, there is one potential issue with the code. Specifically, the line:

const filterWrapper = (wrapper.subMenu || wrapper.submenu).searchSubMenuRenderer.groups;

It's possible that this line could throw a TypeError if neither wrapper.subMenu nor wrapper.submenu is defined, or if the resulting searchSubMenuRenderer is not an object with a groups property. To avoid this potential issue, you may want to add some checks or defensive coding to ensure that the data you're accessing exists before attempting to iterate over it.

For example, you can modify the line as follows to add a safety check:

const filterWrapper = ((wrapper.subMenu || wrapper.submenu)?.searchSubMenuRenderer || {}).groups || [];

This change ensures that filterWrapper will always be an array, even if wrapper.subMenu and wrapper.submenu are undefined or don't have the expected properties.

Other than this, the code looks fine and should work as intended, provided that the input JSON object (json) has the expected structure and properties.

@Fennix900
Copy link

i have run the filterWrapper code thru chatgpt and it give a safety check for the filterWrapper which seems to fix the issue const filterWrapper = ((wrapper.subMenu || wrapper.submenu)?.searchSubMenuRenderer || {}).groups || []; here's the full explanation: The code you provided seems to be a JavaScript module that exports a function parseFilters(json) to parse and extract filter information from a JSON object. The function appears to be used in a search-related context, possibly to parse YouTube search results.

As for non-iterable errors, this code should not produce any non-iterable errors on its own. It seems to be using various iterators like for...of loops to traverse arrays and objects, which are appropriate methods for iterating over iterable data structures in JavaScript.

However, there is one potential issue with the code. Specifically, the line:

const filterWrapper = (wrapper.subMenu || wrapper.submenu).searchSubMenuRenderer.groups;

It's possible that this line could throw a TypeError if neither wrapper.subMenu nor wrapper.submenu is defined, or if the resulting searchSubMenuRenderer is not an object with a groups property. To avoid this potential issue, you may want to add some checks or defensive coding to ensure that the data you're accessing exists before attempting to iterate over it.

For example, you can modify the line as follows to add a safety check:

const filterWrapper = ((wrapper.subMenu || wrapper.submenu)?.searchSubMenuRenderer || {}).groups || [];

This change ensures that filterWrapper will always be an array, even if wrapper.subMenu and wrapper.submenu are undefined or don't have the expected properties.

Other than this, the code looks fine and should work as intended, provided that the input JSON object (json) has the expected structure and properties.

Got the same error.
This solution fixed it for me.
I replaced line 21 in the utils.js with the solution.

@Michal-Szczepaniak
Copy link

Confirmed here (outside us), fix works.

Damn… AI be outsmarting us

@nukeop
Copy link
Author

nukeop commented Aug 5, 2023

It only hides the problem. It stops the function from crashing, but returns no results. So that's no fix. Pasting stuff into chatgpt without thinking is not a solution to anything.

@Michal-Szczepaniak
Copy link

But i got results just fine, though i agree with latter, the fix does indeed work

@Fennix900
Copy link

Maybe, but i got this error and after replacing the line i got the results

@nukeop
Copy link
Author

nukeop commented Aug 5, 2023

How? That "fix" only returns an empty list if both scraped elements are undefined.

@Fennix900
Copy link

How? That "fix" only returns an empty list if both scraped elements are undefined.

Idk, i only know that i got always errors when starting the query and with this "fix" i got results

@nukeop
Copy link
Author

nukeop commented Aug 5, 2023

Then those results are wrong, because you're not applying any filters.

@Michal-Szczepaniak
Copy link

Michal-Szczepaniak commented Aug 5, 2023

Because I am not using filters perhaps? From what i see it will return results but not filters, it doesn't prevent results from returning

whats wrong with not using filters?

Ok so it's not "proper" fix but it does return results if filters are not used, thats what we can agree on

@Fennix900
Copy link

Because I am not using filters perhaps? From what i see it will return results but not filters, it doesn't prevent results from returning

whats wrong with not using filters?

Ok so it's not "proper" fix but it does return results if filters are not used, thats what we can agree on

Agreed, as far as i can tell i get the results i expected or at least the results that i require to work with

@rjdg14
Copy link

rjdg14 commented Aug 5, 2023

i have run the filterWrapper code thru chatgpt and it give a safety check for the filterWrapper which seems to fix the issue const filterWrapper = ((wrapper.subMenu || wrapper.submenu)?.searchSubMenuRenderer || {}).groups || []; here's the full explanation: The code you provided seems to be a JavaScript module that exports a function parseFilters(json) to parse and extract filter information from a JSON object. The function appears to be used in a search-related context, possibly to parse YouTube search results.
As for non-iterable errors, this code should not produce any non-iterable errors on its own. It seems to be using various iterators like for...of loops to traverse arrays and objects, which are appropriate methods for iterating over iterable data structures in JavaScript.
However, there is one potential issue with the code. Specifically, the line:

const filterWrapper = (wrapper.subMenu || wrapper.submenu).searchSubMenuRenderer.groups;

It's possible that this line could throw a TypeError if neither wrapper.subMenu nor wrapper.submenu is defined, or if the resulting searchSubMenuRenderer is not an object with a groups property. To avoid this potential issue, you may want to add some checks or defensive coding to ensure that the data you're accessing exists before attempting to iterate over it.
For example, you can modify the line as follows to add a safety check:

const filterWrapper = ((wrapper.subMenu || wrapper.submenu)?.searchSubMenuRenderer || {}).groups || [];

This change ensures that filterWrapper will always be an array, even if wrapper.subMenu and wrapper.submenu are undefined or don't have the expected properties.
Other than this, the code looks fine and should work as intended, provided that the input JSON object (json) has the expected structure and properties.

Got the same error. This solution fixed it for me. I replaced line 21 in the utils.js with the solution.

Can you tell me where utils.js file that you're talking about is? FreeTube is no doubt in need of an update and I have it installed on my computer with this very problem (which has been occuring for several months), yet I can't find the file you're talking about anywhere in my installation (it's a user-side installation in the Windows AppData folder).

@SeiRann
Copy link

SeiRann commented Aug 9, 2023

node_modules/ytsr/lib/utils.js

@Michal-Szczepaniak
Copy link

Isn't this fixed by #203?

@stale
Copy link

stale bot commented Oct 15, 2023

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Oct 15, 2023
@stale stale bot closed this as completed Dec 15, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

10 participants