How can I resolve a pagination error in my collection page?

i am facing this error

Liquid error (templates/404 line 39): Array ‘collection.products’ is not paginateable.

{%- liquid

Determine the number of products per page

if cart.attributes.pagination != blank and cart.attributes.pagination
assign products_per_page = 2
else
assign products_per_page = 3
endif
-%}

{{ page_title }}

  • Home
  • {{ 'Shop Pages' }}

{%- paginate collection.products by products_per_page -%}
{% comment %} {{ collection.products | json }} {% endcomment %}

Showing 1–{{ collection.products_count }} of {{ collection.products_count }} results

{{ 'Filters' }}

{% comment %} {% endcomment %}

{{ 'Sort By' }}
    {% assign sort_by = collection.sort_by | default: collection.default_sort_by %}

    {% for option in collection.sort_options %}

  • {{ option.name }}
  • {% endfor %}

{% comment %}

{{ 'Categories' }}

    {% assign available_categories = collection.products | map: 'product.type' | compact | uniq %}

    {% for product in collection.products %}

    {{ product.type }}

    {% endfor %}
{% endcomment %}

{{ 'Price' }}

{% comment %}

{{ 'Prices' }}

    {% assign available_prices = collection.products | map: 'price' | compact | uniq %}

    {% for price in available_prices %}

  • {{ price | money }}
  • {% endfor %}
{% endcomment %}

{{ 'Brands' }}

    {% assign available_tags = collection.all_tags | compact | uniq %} {% for tag in available_tags %}
  • {{ tag }}
  • {% endfor %}

{{ 'Colors' }}

    {% assign available_colors = collection.products | map: 'variants' | map: 'option2' | compact | uniq %} {% for color in available_colors %}
  • {{ color }}
  • {% endfor %}

{{ 'Sizes' }}

    {% assign available_sizes = collection.products | map: 'variants' | map: 'option1' | compact | uniq %} {% for size in available_sizes %}
  • {{ size }}
  • {% endfor %}
{%- if collection.products.size > 0 -%}
{% for product in collection.products %} {% assign product_color = product.variants.first.option2 %}

Color in URL: {{ request.params.color }}

{% if request.params.color == product_color %}

{{ product.title }}

{{ product.price | money }} {% if product.compare_at_price > product.price %} {{ product.compare_at_price | money }} {% endif %}

{{ product.description | truncate: 150 }}

{% endif %} {% endfor %}
{%- if paginate.pages > 1 -%} {% render 'pagination-listing', paginate: paginate, show_infinite_scrolling: show_infinite_scrolling, anchor: '', class: 'pagination-wrapper text-center' %} {%- endif -%} {%- endif -%}
{% endpaginate %}

{% comment %} {% comment %}

// {% endcomment %} {% endcomment %}