Shopify / Shopify/liquid

Excluding errors from output

Open
#1,950 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Feature Request
Dominant language
Ruby
Stars
11.9k
Forks
1.5k
Avg merge
17h 55m
Merged PRs (30d)
3

Description

Hey,

I believe that showing errors is the right default for Shopify as a platform. However, I am taking a modular approach to building Shopify themes, and it would be helpful to have a safe option to opt out of this feature.

Please consider having a way to deal with errors that's not based on strings.

Example

I have a reference theme that uses an icon via a liquid snippet:

{{- 'icon-' | append: 'default' | append: '-' | append: icon | append: '.svg' | inline_asset_content -}}

To override the default icon in a project, I want to check if a custom icon exists. If it doesn't exist, I will fall back to the default icon:

{%- liquid
  capture custom_svg
    echo 'custom-' | append: 'icon-' | append: 'default' | append: '-' | append: icon | append: '.svg' | inline_asset_content
  endcapture

  if custom_svg_tag != blank
    echo custom_svg
  else
    echo 'icon-' | append: 'default' | append: '-' | append: icon | append: '.svg' | inline_asset_content
  endif
-%}

This doesn't work because custom_svg contains an error instead of being empty. Now, I'm forced to look for an error message or validating the output:

assign custom_svg_tag = custom_svg | slice: 0, 5

if custom_svg_tag == '<svg'
  echo custom_svg
else
  echo 'icon-' | append: 'default' | append: '-' | append: icon | append: '.svg' | inline_asset_content
endif

This is definitely not optimal. We have tried this approach for translations in the past, and the error message changed a few times, causing our setup to break.

Another important use case with the same approach is rendering snippets. If there is a custom- version of a snippet it should be used, else it should use the default.

Suggestions

From favorite to least favorite:

  1. | or_blank or | filter_errors filter to replace errors with blank. Usage: assign custom_svg = custom_svg_raw | or_blank if custom_svg != blank
  2. error as a value similar to blank or empty. Usage: if custom_svg != error
  3. trycapture tag. Usage {% trycapture %}{% endtrycapture%}
  4. Last resort is to disable outputting errors for a file somehow

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

No repository files or tests are named. Start by locating the implementation and tests for captured error output and the inline_asset_content behavior; done means providing a stable, non-string-based way to detect or suppress errors for fallback rendering without breaking existing error output.

Written by the indexing model from the issue text.

Assessment

Domain
web-dev
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.