Shopify / theme-check

The Ultimate Shopify Theme Linter
Other
334 stars 96 forks source link

"Auto-fix" of Swym snippet crashes the server and literally deletes the file. #652

Closed ConduciveMammal closed 1 week ago

ConduciveMammal commented 1 year ago

Describe the bug So, in the process of installing Swym wishlist onto a theme, when I create a new file called swym-product-view.liquid and then auto-fix any issues, theme-check server will first crash and then somehow delete the entire file.

Here is the code from the snippet:

{% if product %}
  <script class="swym-product-view-snippet">
  ['SwymViewProducts', 'SwymWatchProducts', 'SwymProductVariants'].forEach(function(k){
    if(!window[k]) window[k] = {};
  });
  (function(et){
      var collections = {{product.type | json}};
      var o={}, empi={{ product.id | json }},
      piu = {{ product.featured_image | json }};
      {% assign currentVariant = product.variants[0] %}
      {% for variant in product.variants %}
      {% if variant.selected %}
      {% assign currentVariant = variant %}
      {% endif %}
      SwymProductVariants[{{variant.id|json}}] = {
        empi:empi,epi:{{variant.id|json}},
        du:"{{ shop.url }}{{ product.url }}",
        dt:{{ product.title | json }},
        iu: {{ variant.image.src | json}} || piu,
        stk: {{variant.inventory_quantity}},
        pr: {{ variant.price }}/100,
        {% if variant.compare_at_price %} op: {{variant.compare_at_price}}/100, {% endif %}
        variants: [{ {{ variant.title | json }} : {{variant.id|json}}}]
      };
      SwymWatchProducts[{{variant.id | json}}] = o[{{variant.id | json}}] = {"id": {{variant.id | json}}, "available": {{variant.available | json}},"inventory_management": {{variant.inventory_management | json}},"inventory_quantity": {{variant.inventory_quantity | json}},"title": {{variant.title | json}}, "inventory_policy": {{variant.inventory_policy | json}}};
      {% endfor %}
      var product_data = {
        empi:empi, epi:{{ currentVariant.id }},
        dt  :{{ product.title | json }},du:"{{ shop.url }}{{ product.url }}",
        ct  :collections,pr:{{ currentVariant.price }}/100,stk:{{ currentVariant.inventory_quantity }},
        iu  :{{ currentVariant.image.src | json }} || piu,variants:[{ {{currentVariant.title | json}} : {{currentVariant.id | json}} }]
        {% if currentVariant.compare_at_price %} ,op:{{currentVariant.compare_at_price}}/100 {% endif %}
      };
      SwymViewProducts[{{product.handle | json}}] = SwymViewProducts[{{product.id | json}}] = product_data;
      SwymWatchProducts[{{product.handle | json}}] = SwymWatchProducts[{{product.id | json}}] = o;
    })();

  </script>
  {% endif %}

Steps to reproduce

Stack trace

rescuing NoMethodError in handler thread
Fatal NoMethodError
/usr/local/Cellar/theme-check/1.11.0/gems/theme-check-1.11.0/lib/theme_check/theme_file.rb:47:in `source': undefined method `include?' for nil:NilClass (NoMethodError)
    from /usr/local/Cellar/theme-check/1.11.0/gems/theme-check-1.11.0/lib/theme_check/liquid_file.rb:55:in `parse'
    from /usr/local/Cellar/theme-check/1.11.0/gems/theme-check-1.11.0/lib/theme_check/liquid_file.rb:63:in `root'
    from /usr/local/Cellar/theme-check/1.11.0/gems/theme-check-1.11.0/lib/theme_check/liquid_visitor.rb:12:in `visit_liquid_file'
    from /usr/local/Cellar/theme-check/1.11.0/gems/theme-check-1.11.0/lib/theme_check/analyzer.rb:112:in `block (2 levels) in analyze_files'
    from /usr/local/Cellar/theme-check/1.11.0/gems/theme-check-1.11.0/lib/theme_check/analyzer.rb:109:in `each'
    from /usr/local/Cellar/theme-check/1.11.0/gems/theme-check-1.11.0/lib/theme_check/analyzer.rb:109:in `each_with_index'
    from /usr/local/Cellar/theme-check/1.11.0/gems/theme-check-1.11.0/lib/theme_check/analyzer.rb:109:in `block in analyze_files'
    from /usr/local/Cellar/theme-check/1.11.0/gems/theme-check-1.11.0/lib/theme_check.rb:68:in `with_liquid_c_disabled'
    from /usr/local/Cellar/theme-check/1.11.0/gems/theme-check-1.11.0/lib/theme_check/analyzer.rb:84:in `analyze_files'
    from /usr/local/Cellar/theme-check/1.11.0/gems/theme-check-1.11.0/lib/theme_check/language_server/diagnostics_engine.rb:85:in `block in run_partial_theme_check'
    from /usr/local/Cellar/ruby/3.1.2_1/lib/ruby/3.1.0/benchmark.rb:296:in `measure'
    from /usr/local/Cellar/theme-check/1.11.0/gems/theme-check-1.11.0/lib/theme_check/language_server/diagnostics_engine.rb:84:in `run_partial_theme_check'
    from /usr/local/Cellar/theme-check/1.11.0/gems/theme-check-1.11.0/lib/theme_check/language_server/diagnostics_engine.rb:30:in `analyze_and_send_offenses'
    from /usr/local/Cellar/theme-check/1.11.0/gems/theme-check-1.11.0/lib/theme_check/language_server/handler.rb:276:in `analyze_and_send_offenses'
    from /usr/local/Cellar/theme-check/1.11.0/gems/theme-check-1.11.0/lib/theme_check/language_server/handler.rb:112:in `on_text_document_did_change'
    from /usr/local/Cellar/theme-check/1.11.0/gems/theme-check-1.11.0/lib/theme_check/language_server/server.rb:138:in `handle_message'
    from /usr/local/Cellar/theme-check/1.11.0/gems/theme-check-1.11.0/lib/theme_check/language_server/server.rb:109:in `block in handle_messages'
    from /usr/local/Cellar/theme-check/1.11.0/gems/theme-check-1.11.0/lib/theme_check/language_server/server.rb:105:in `loop'
    from /usr/local/Cellar/theme-check/1.11.0/gems/theme-check-1.11.0/lib/theme_check/language_server/server.rb:105:in `handle_messages'
    from /usr/local/Cellar/theme-check/1.11.0/gems/theme-check-1.11.0/lib/theme_check/language_server/server.rb:99:in `block (2 levels) in start_handler_threads'
Closing server... status code = 2
rescuing ThemeCheck::LanguageServer::DoneStreaming in jsonrpc thread
[Info  - 12:45:23] Connection to server got closed. Server will restart.
[Error - 12:45:23] Request textDocument/codeAction failed.
Error: Connection got disposed.
    at Object.dispose (/Users/liammerlyn/.vscode/extensions/shopify.theme-check-vscode-1.7.0/dist/extension.js:406:278142)
    at Object.dispose (/Users/liammerlyn/.vscode/extensions/shopify.theme-check-vscode-1.7.0/dist/extension.js:406:358314)
    at E.handleConnectionClosed (/Users/liammerlyn/.vscode/extensions/shopify.theme-check-vscode-1.7.0/dist/extension.js:406:358527)
    at E.handleConnectionClosed (/Users/liammerlyn/.vscode/extensions/shopify.theme-check-vscode-1.7.0/dist/extension.js:406:418915)
    at t (/Users/liammerlyn/.vscode/extensions/shopify.theme-check-vscode-1.7.0/dist/extension.js:406:356616)
    at i.invoke (/Users/liammerlyn/.vscode/extensions/shopify.theme-check-vscode-1.7.0/dist/extension.js:406:279755)
    at o.fire (/Users/liammerlyn/.vscode/extensions/shopify.theme-check-vscode-1.7.0/dist/extension.js:406:280516)
    at X (/Users/liammerlyn/.vscode/extensions/shopify.theme-check-vscode-1.7.0/dist/extension.js:406:267400)
    at i.invoke (/Users/liammerlyn/.vscode/extensions/shopify.theme-check-vscode-1.7.0/dist/extension.js:406:279755)
    at o.fire (/Users/liammerlyn/.vscode/extensions/shopify.theme-check-vscode-1.7.0/dist/extension.js:406:280516)
    at f.fireClose (/Users/liammerlyn/.vscode/extensions/shopify.theme-check-vscode-1.7.0/dist/extension.js:406:291969)
    at Socket.<anonymous> (/Users/liammerlyn/.vscode/extensions/shopify.theme-check-vscode-1.7.0/dist/extension.js:406:292754)
    at Socket.emit (node:events:526:28)
    at Pipe.<anonymous> (node:net:687:12)
[Error - 12:45:23] Request textDocument/documentLink failed.
Error: Connection got disposed.
    at Object.dispose (/Users/liammerlyn/.vscode/extensions/shopify.theme-check-vscode-1.7.0/dist/extension.js:406:278142)
    at Object.dispose (/Users/liammerlyn/.vscode/extensions/shopify.theme-check-vscode-1.7.0/dist/extension.js:406:358314)
    at E.handleConnectionClosed (/Users/liammerlyn/.vscode/extensions/shopify.theme-check-vscode-1.7.0/dist/extension.js:406:358527)
    at E.handleConnectionClosed (/Users/liammerlyn/.vscode/extensions/shopify.theme-check-vscode-1.7.0/dist/extension.js:406:418915)
    at t (/Users/liammerlyn/.vscode/extensions/shopify.theme-check-vscode-1.7.0/dist/extension.js:406:356616)
    at i.invoke (/Users/liammerlyn/.vscode/extensions/shopify.theme-check-vscode-1.7.0/dist/extension.js:406:279755)
    at o.fire (/Users/liammerlyn/.vscode/extensions/shopify.theme-check-vscode-1.7.0/dist/extension.js:406:280516)
    at X (/Users/liammerlyn/.vscode/extensions/shopify.theme-check-vscode-1.7.0/dist/extension.js:406:267400)
    at i.invoke (/Users/liammerlyn/.vscode/extensions/shopify.theme-check-vscode-1.7.0/dist/extension.js:406:279755)
    at o.fire (/Users/liammerlyn/.vscode/extensions/shopify.theme-check-vscode-1.7.0/dist/extension.js:406:280516)
    at f.fireClose (/Users/liammerlyn/.vscode/extensions/shopify.theme-check-vscode-1.7.0/dist/extension.js:406:291969)
    at Socket.<anonymous> (/Users/liammerlyn/.vscode/extensions/shopify.theme-check-vscode-1.7.0/dist/extension.js:406:292754)
    at Socket.emit (node:events:526:28)
    at Pipe.<anonymous> (node:net:687:12)
[Error - 12:45:23] Request textDocument/codeAction failed.
Error: Connection got disposed.
    at Object.dispose (/Users/liammerlyn/.vscode/extensions/shopify.theme-check-vscode-1.7.0/dist/extension.js:406:278142)
    at Object.dispose (/Users/liammerlyn/.vscode/extensions/shopify.theme-check-vscode-1.7.0/dist/extension.js:406:358314)
    at E.handleConnectionClosed (/Users/liammerlyn/.vscode/extensions/shopify.theme-check-vscode-1.7.0/dist/extension.js:406:358527)
    at E.handleConnectionClosed (/Users/liammerlyn/.vscode/extensions/shopify.theme-check-vscode-1.7.0/dist/extension.js:406:418915)
    at t (/Users/liammerlyn/.vscode/extensions/shopify.theme-check-vscode-1.7.0/dist/extension.js:406:356616)
    at i.invoke (/Users/liammerlyn/.vscode/extensions/shopify.theme-check-vscode-1.7.0/dist/extension.js:406:279755)
    at o.fire (/Users/liammerlyn/.vscode/extensions/shopify.theme-check-vscode-1.7.0/dist/extension.js:406:280516)
    at X (/Users/liammerlyn/.vscode/extensions/shopify.theme-check-vscode-1.7.0/dist/extension.js:406:267400)
    at i.invoke (/Users/liammerlyn/.vscode/extensions/shopify.theme-check-vscode-1.7.0/dist/extension.js:406:279755)
    at o.fire (/Users/liammerlyn/.vscode/extensions/shopify.theme-check-vscode-1.7.0/dist/extension.js:406:280516)
    at f.fireClose (/Users/liammerlyn/.vscode/extensions/shopify.theme-check-vscode-1.7.0/dist/extension.js:406:291969)
    at Socket.<anonymous> (/Users/liammerlyn/.vscode/extensions/shopify.theme-check-vscode-1.7.0/dist/extension.js:406:292754)
    at Socket.emit (node:events:526:28)
    at Pipe.<anonymous> (node:net:687:12)
[Error - 12:45:23] Request textDocument/documentLink failed.
Error: Connection got disposed.
    at Object.dispose (/Users/liammerlyn/.vscode/extensions/shopify.theme-check-vscode-1.7.0/dist/extension.js:406:278142)
    at Object.dispose (/Users/liammerlyn/.vscode/extensions/shopify.theme-check-vscode-1.7.0/dist/extension.js:406:358314)
    at E.handleConnectionClosed (/Users/liammerlyn/.vscode/extensions/shopify.theme-check-vscode-1.7.0/dist/extension.js:406:358527)
    at E.handleConnectionClosed (/Users/liammerlyn/.vscode/extensions/shopify.theme-check-vscode-1.7.0/dist/extension.js:406:418915)
    at t (/Users/liammerlyn/.vscode/extensions/shopify.theme-check-vscode-1.7.0/dist/extension.js:406:356616)
    at i.invoke (/Users/liammerlyn/.vscode/extensions/shopify.theme-check-vscode-1.7.0/dist/extension.js:406:279755)
    at o.fire (/Users/liammerlyn/.vscode/extensions/shopify.theme-check-vscode-1.7.0/dist/extension.js:406:280516)
    at X (/Users/liammerlyn/.vscode/extensions/shopify.theme-check-vscode-1.7.0/dist/extension.js:406:267400)
    at i.invoke (/Users/liammerlyn/.vscode/extensions/shopify.theme-check-vscode-1.7.0/dist/extension.js:406:279755)
    at o.fire (/Users/liammerlyn/.vscode/extensions/shopify.theme-check-vscode-1.7.0/dist/extension.js:406:280516)
    at f.fireClose (/Users/liammerlyn/.vscode/extensions/shopify.theme-check-vscode-1.7.0/dist/extension.js:406:291969)
    at Socket.<anonymous> (/Users/liammerlyn/.vscode/extensions/shopify.theme-check-vscode-1.7.0/dist/extension.js:406:292754)
    at Socket.emit (node:events:526:28)
    at Pipe.<anonymous> (node:net:687:12)
[Error - 12:45:23] Request textDocument/codeAction failed.
Error: Connection got disposed.
    at Object.dispose (/Users/liammerlyn/.vscode/extensions/shopify.theme-check-vscode-1.7.0/dist/extension.js:406:278142)
    at Object.dispose (/Users/liammerlyn/.vscode/extensions/shopify.theme-check-vscode-1.7.0/dist/extension.js:406:358314)
    at E.handleConnectionClosed (/Users/liammerlyn/.vscode/extensions/shopify.theme-check-vscode-1.7.0/dist/extension.js:406:358527)
    at E.handleConnectionClosed (/Users/liammerlyn/.vscode/extensions/shopify.theme-check-vscode-1.7.0/dist/extension.js:406:418915)
    at t (/Users/liammerlyn/.vscode/extensions/shopify.theme-check-vscode-1.7.0/dist/extension.js:406:356616)
    at i.invoke (/Users/liammerlyn/.vscode/extensions/shopify.theme-check-vscode-1.7.0/dist/extension.js:406:279755)
    at o.fire (/Users/liammerlyn/.vscode/extensions/shopify.theme-check-vscode-1.7.0/dist/extension.js:406:280516)
    at X (/Users/liammerlyn/.vscode/extensions/shopify.theme-check-vscode-1.7.0/dist/extension.js:406:267400)
    at i.invoke (/Users/liammerlyn/.vscode/extensions/shopify.theme-check-vscode-1.7.0/dist/extension.js:406:279755)
    at o.fire (/Users/liammerlyn/.vscode/extensions/shopify.theme-check-vscode-1.7.0/dist/extension.js:406:280516)
    at f.fireClose (/Users/liammerlyn/.vscode/extensions/shopify.theme-check-vscode-1.7.0/dist/extension.js:406:291969)
    at Socket.<anonymous> (/Users/liammerlyn/.vscode/extensions/shopify.theme-check-vscode-1.7.0/dist/extension.js:406:292754)
    at Socket.emit (node:events:526:28)
    at Pipe.<anonymous> (node:net:687:12)
[Error - 12:45:23] Request textDocument/codeAction failed.
Error: Connection got disposed.
    at Object.dispose (/Users/liammerlyn/.vscode/extensions/shopify.theme-check-vscode-1.7.0/dist/extension.js:406:278142)
    at Object.dispose (/Users/liammerlyn/.vscode/extensions/shopify.theme-check-vscode-1.7.0/dist/extension.js:406:358314)
    at E.handleConnectionClosed (/Users/liammerlyn/.vscode/extensions/shopify.theme-check-vscode-1.7.0/dist/extension.js:406:358527)
    at E.handleConnectionClosed (/Users/liammerlyn/.vscode/extensions/shopify.theme-check-vscode-1.7.0/dist/extension.js:406:418915)
    at t (/Users/liammerlyn/.vscode/extensions/shopify.theme-check-vscode-1.7.0/dist/extension.js:406:356616)
    at i.invoke (/Users/liammerlyn/.vscode/extensions/shopify.theme-check-vscode-1.7.0/dist/extension.js:406:279755)
    at o.fire (/Users/liammerlyn/.vscode/extensions/shopify.theme-check-vscode-1.7.0/dist/extension.js:406:280516)
    at X (/Users/liammerlyn/.vscode/extensions/shopify.theme-check-vscode-1.7.0/dist/extension.js:406:267400)
    at i.invoke (/Users/liammerlyn/.vscode/extensions/shopify.theme-check-vscode-1.7.0/dist/extension.js:406:279755)
    at o.fire (/Users/liammerlyn/.vscode/extensions/shopify.theme-check-vscode-1.7.0/dist/extension.js:406:280516)
    at f.fireClose (/Users/liammerlyn/.vscode/extensions/shopify.theme-check-vscode-1.7.0/dist/extension.js:406:291969)
    at Socket.<anonymous> (/Users/liammerlyn/.vscode/extensions/shopify.theme-check-vscode-1.7.0/dist/extension.js:406:292754)
    at Socket.emit (node:events:526:28)
    at Pipe.<anonymous> (node:net:687:12)
[Error - 12:45:23] Request textDocument/documentLink failed.
Error: Connection got disposed.
    at Object.dispose (/Users/liammerlyn/.vscode/extensions/shopify.theme-check-vscode-1.7.0/dist/extension.js:406:278142)
    at Object.dispose (/Users/liammerlyn/.vscode/extensions/shopify.theme-check-vscode-1.7.0/dist/extension.js:406:358314)
    at E.handleConnectionClosed (/Users/liammerlyn/.vscode/extensions/shopify.theme-check-vscode-1.7.0/dist/extension.js:406:358527)
    at E.handleConnectionClosed (/Users/liammerlyn/.vscode/extensions/shopify.theme-check-vscode-1.7.0/dist/extension.js:406:418915)
    at t (/Users/liammerlyn/.vscode/extensions/shopify.theme-check-vscode-1.7.0/dist/extension.js:406:356616)
    at i.invoke (/Users/liammerlyn/.vscode/extensions/shopify.theme-check-vscode-1.7.0/dist/extension.js:406:279755)
    at o.fire (/Users/liammerlyn/.vscode/extensions/shopify.theme-check-vscode-1.7.0/dist/extension.js:406:280516)
    at X (/Users/liammerlyn/.vscode/extensions/shopify.theme-check-vscode-1.7.0/dist/extension.js:406:267400)
    at i.invoke (/Users/liammerlyn/.vscode/extensions/shopify.theme-check-vscode-1.7.0/dist/extension.js:406:279755)
    at o.fire (/Users/liammerlyn/.vscode/extensions/shopify.theme-check-vscode-1.7.0/dist/extension.js:406:280516)
    at f.fireClose (/Users/liammerlyn/.vscode/extensions/shopify.theme-check-vscode-1.7.0/dist/extension.js:406:291969)
    at Socket.<anonymous> (/Users/liammerlyn/.vscode/extensions/shopify.theme-check-vscode-1.7.0/dist/extension.js:406:292754)
    at Socket.emit (node:events:526:28)
    at Pipe.<anonymous> (node:net:687:12)

Debugging information

Additional context Video of issue

lukeh-shopify commented 1 week ago

šŸ‘‹šŸ» Hi @ConduciveMammal! Thanks for reporting this. Unfortunately the Ruby version of theme check has been deprecated for some time. Would you be able to confirm you are still having issues when using our maintained version of theme check? This is done using either the latest version of the Shopify CLI, or via the Shopify Liquid Visual Studio Code extension.

If you are still having issues, please raise an issue over in the CLI or theme tools repositories. Thanks!