A developer is troubleshooting an intermittent “Liquid error (sections/main-collection line 898): internal” that occurs when loading paginated product collections in Shopify. The error appears infrequently—sometimes going weeks without occurring—making it difficult to diagnose.
Initial attempts:
Checking collection.products.first before looping
Using collection.products.size > 0 condition
Both approaches still produced the error
Key insights from community:
The error predates recent code changes and occurred even with the previous theme
Checking for collection.products.first before the loop may be problematic
Using {% unless collection.empty? %} is more reliable than {% if collection %} since empty objects evaluate as truthy in Liquid
Solution implemented:
Wrap the code in a {% capture %} block to catch errors
Use {% if output contains "Liquid error (" %} to detect when errors occur
Display a graceful error message instead of showing the raw Liquid error
Utilize the {% else %} clause within the for loop for empty collections
The issue is now handled gracefully with proper error detection, though the root cause of the intermittent “internal” error remains unclear.
Summarized with AI on October 29.
AI used: claude-sonnet-4-5-20250929.
I have been running into an internal error when the Shopify website I’m working on attempts to load a paginated list of store products. The error is usually very rare but recently has shown up more frequently (could go weeks without showing up once):
Liquid error (sections/main-collection line 898): internal
The error is not very clear and I have no clue if “internal,” is in reference to my code, or something to do with Shopify.
In any case, here is one attempt at the code which was working fairly decently until one day this error started showing up infrequently:
{% if collection %}
{% if collection.products.first %} // → this line throws the error
{%- for product in collection.products -%}
{%- render ‘product-item’, product: product, list: show_as_list, grid_classes: grid_classes -%}
{%- endfor -%}
{% else %}
Some easy to understand error message to user
{% endif %}
{% endif %}
I have also tried {% if collection and collection.products.size > 0 %} but still no luck.
If it helps, 48 products are loaded per page. I kind of think it may be loading too many products at once, but 50 is the default so I’m not sure.
If anyone knows what might be the issue and either a possible solution, or even a way to handle the error gracefully, I would greatly appreciate the help!
Actually this has been an issue even before I started working on the site.
Apparently it even happened with the old theme, but it would just show an empty page.
I’ve been trying to do as much error checking as necessary to minimize the problem, but it happens so rarely that I can’t really determine the nature of the error. Worst of all is that I can’t really log out the collections object to see what’s wrong with it (undefined, null, etc.)
{% capture output %}
{% if collection %}
{%- for product in collection.products -%}
{%- render 'product-item', product: product, list: show_as_list, grid_classes: grid_classes -%}
{% else %}
Some easy to understand error message to user
{%- endfor -%}
{% endif %}
{% endcapture %}
{% assign output = output | strip %}
{% if output == "internal" %}
error handling here
{% else %}
{{ output }}
{% endif %}
Also, I do not know where are you’re getting your collection variable from, but if, say collection is a string, then {% if collection %} would still be true, but collection.products will generate error. Even empty object is true! https://shopify.dev/docs/api/liquid/basics#truthy-and-falsy
An empty object is returned if you try to access an object that is defined, but has no value. For example a page or product that’s been deleted, or a setting with no value.> > You can compare an object with empty to check whether an object exists before you access any of its attributes.