Skip to content

Excluding errors from output #1950

@wiebekaai

Description

@wiebekaai

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions