Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: remove invalid email template #261

Merged
merged 1 commit into from
Jul 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,7 @@ This directory is built automatically. Each task's documentation is generated fr
* [Catalog update email](./catalog-update-email)
* [Email someone specific based on a new order's customer tags](./email-someone-specific-based-on-a-new-orders-customer-tags)
* [Email someone when a certain product is purchased](./email-someone-when-certain-product-purchased)
* [Error reporter](./error-reporter)
* [Flag orders that aren't fulfilled after several days](./flag-orders-that-arent-fulfilled-after-two-days)
* [Get email alerts for FBA failures](./get-email-alerts-for-fba-failures)
* [Get email alerts for out of stock products](./get-email-alerts-for-out-of-stock-products)
Expand Down
2 changes: 1 addition & 1 deletion docs/error-reporter/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Error reporter

Tags: Error
Tags: Alert, Error

Use this task to get email reports when errors occur with events, tasks, and actions in Mechanic. Use this task out of the box, customize it, or borrow logic for your more advanced error reporting tasks.

Expand Down
23 changes: 14 additions & 9 deletions docs/error-reporter/script.liquid
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,8 @@
{% assign error_thresholds[4] = 200 %}

{% comment %}
Fingerprinting the error, so that we can track if this is something
we have received recently.

See: https://learn.mechanic.dev/techniques/debouncing-events#fingerprinting
Fingerprinting the error, so that we can track if this is something we have received recently.
See: https://learn.mechanic.dev/techniques/debouncing-events#fingerprinting
{% endcomment %}

{% assign fingerprint_parts = hash %}
Expand All @@ -25,6 +23,7 @@
{% assign error_count_cache_key = "errors/" | append: fingerprint %}

{% comment %} How many times have we seen this error recently? {% endcomment %}

{% assign recent_error_count = cache[error_count_cache_key] | default: 0 %}

{% assign event_url = "https://admin.shopify.com/store/" | append: shop.domain | replace: ".myshopify.com", "/apps/mechanic/events/" | append: error.event.id %}
Expand All @@ -34,13 +33,17 @@
{%- endcapture %}

{% capture email_body %}
<p><b>This an automated error notification from your Mechanic error reporting task.</b></p>
<p><b>This is an automated error notification from your Mechanic error reporting task.</b></p>

{% if error_thresholds contains recent_error_count -%}
<p><b>Note:</b> There have been more than {{ recent_error_count }} errors of this type in the last 10 minutes.</p>
{%- endif %}
<p><b>Note:</b> There have been more than {{ recent_error_count }} errors of this type in the last 10 minutes.</p>
{%- endif %}

<p><a href="{{ event_url }}">View error details</a></p>
{% if event.preview %}
<p>View error details</p>
{% else %}
<p><a href="{{ event_url }}">View error details</a></p>
{% endif %}

<p>Error topic: {{ event.topic }}</p>

Expand All @@ -52,13 +55,14 @@
{% comment %}
We only send emails on the first error and again on specific thresholds
{% endcomment %}

{% if recent_error_count == 0 or error_thresholds contains recent_error_count %}
{% action "email" %}
{
"to": {{ options.email_recipients__email_array_required | json }},
"subject": {{ email_subject | json }},
"template": "default_matt",
"body": {{ email_body | json }},
"reply_to": {{ shop.customer_email | json }},
"from_display_name": {{ shop.name | json }}
}
{% endaction %}
Expand All @@ -67,6 +71,7 @@
{% comment %}
Increment recent error count for this error
{% endcomment %}

{% action "cache" %}
{
"incr": {
Expand Down
6 changes: 2 additions & 4 deletions tasks/error-reporter.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,12 @@
}
}
],
"script": "{% comment %}\n Only send error emails for the same errors at these thresholds.\n{% endcomment %}\n\n{% assign error_thresholds = array %}\n{% assign error_thresholds[0] = 10 %}\n{% assign error_thresholds[1] = 25 %}\n{% assign error_thresholds[2] = 50 %}\n{% assign error_thresholds[3] = 100 %}\n{% assign error_thresholds[4] = 200 %}\n\n{% comment %}\n Fingerprinting the error, so that we can track if this is something\n we have received recently.\n\n See: https://learn.mechanic.dev/techniques/debouncing-events#fingerprinting \n{% endcomment %}\n\n{% assign fingerprint_parts = hash %}\n{% assign fingerprint_parts[\"topic\"] = event.topic %}\n{% assign fingerprint_parts[\"message\"] = error.message %}\n{% assign fingerprint_parts[\"task_id\"] = error.task.id %}\n{% assign fingerprint_parts[\"action_type\"] = error.action.type %}\n{% assign fingerprint = fingerprint_parts | json | sha256 %}\n{% assign error_count_cache_key = \"errors/\" | append: fingerprint %}\n\n{% comment %} How many times have we seen this error recently? {% endcomment %}\n{% assign recent_error_count = cache[error_count_cache_key] | default: 0 %}\n\n{% assign event_url = \"https://admin.shopify.com/store/\" | append: shop.domain | replace: \".myshopify.com\", \"/apps/mechanic/events/\" | append: error.event.id %}\n\n{% capture email_subject -%}\n {{ event.topic }} on {{ shop.name }}\n{%- endcapture %}\n\n{% capture email_body %}\n<p><b>This an automated error notification from your Mechanic error reporting task.</b></p>\n\n{% if error_thresholds contains recent_error_count -%}\n <p><b>Note:</b> There have been more than {{ recent_error_count }} errors of this type in the last 10 minutes.</p>\n{%- endif %} \n\n<p><a href=\"{{ event_url }}\">View error details</a></p>\n\n<p>Error topic: {{ event.topic }}</p>\n\n<p>Error message: <pre>{{ error.message }}</pre></p>\n\n<p>Thanks,<br><br>{{ shop.name }} via Mechanic</p>\n{% endcapture %}\n\n{% comment %}\n We only send emails on the first error and again on specific thresholds\n{% endcomment %}\n{% if recent_error_count == 0 or error_thresholds contains recent_error_count %}\n {% action \"email\" %}\n {\n \"to\": {{ options.email_recipients__email_array_required | json }},\n \"subject\": {{ email_subject | json }},\n \"template\": \"default_matt\",\n \"body\": {{ email_body | json }},\n \"from_display_name\": {{ shop.name | json }}\n }\n {% endaction %}\n{% endif %}\n\n{% comment %}\n Increment recent error count for this error\n{% endcomment %}\n{% action \"cache\" %}\n {\n \"incr\": {\n \"key\": {{ fingerprint | json }},\n \"ttl\": 600\n }\n }\n{% endaction %}",
"script": "{% comment %}\n Only send error emails for the same errors at these thresholds.\n{% endcomment %}\n\n{% assign error_thresholds = array %}\n{% assign error_thresholds[0] = 10 %}\n{% assign error_thresholds[1] = 25 %}\n{% assign error_thresholds[2] = 50 %}\n{% assign error_thresholds[3] = 100 %}\n{% assign error_thresholds[4] = 200 %}\n\n{% comment %}\n Fingerprinting the error, so that we can track if this is something we have received recently.\n See: https://learn.mechanic.dev/techniques/debouncing-events#fingerprinting\n{% endcomment %}\n\n{% assign fingerprint_parts = hash %}\n{% assign fingerprint_parts[\"topic\"] = event.topic %}\n{% assign fingerprint_parts[\"message\"] = error.message %}\n{% assign fingerprint_parts[\"task_id\"] = error.task.id %}\n{% assign fingerprint_parts[\"action_type\"] = error.action.type %}\n{% assign fingerprint = fingerprint_parts | json | sha256 %}\n{% assign error_count_cache_key = \"errors/\" | append: fingerprint %}\n\n{% comment %} How many times have we seen this error recently? {% endcomment %}\n\n{% assign recent_error_count = cache[error_count_cache_key] | default: 0 %}\n\n{% assign event_url = \"https://admin.shopify.com/store/\" | append: shop.domain | replace: \".myshopify.com\", \"/apps/mechanic/events/\" | append: error.event.id %}\n\n{% capture email_subject -%}\n {{ event.topic }} on {{ shop.name }}\n{%- endcapture %}\n\n{% capture email_body %}\n<p><b>This is an automated error notification from your Mechanic error reporting task.</b></p>\n\n{% if error_thresholds contains recent_error_count -%}\n <p><b>Note:</b> There have been more than {{ recent_error_count }} errors of this type in the last 10 minutes.</p>\n{%- endif %}\n\n{% if event.preview %}\n <p>View error details</p>\n{% else %}\n <p><a href=\"{{ event_url }}\">View error details</a></p>\n{% endif %}\n\n<p>Error topic: {{ event.topic }}</p>\n\n<p>Error message: <pre>{{ error.message }}</pre></p>\n\n<p>Thanks,<br><br>{{ shop.name }} via Mechanic</p>\n{% endcapture %}\n\n{% comment %}\n We only send emails on the first error and again on specific thresholds\n{% endcomment %}\n\n{% if recent_error_count == 0 or error_thresholds contains recent_error_count %}\n {% action \"email\" %}\n {\n \"to\": {{ options.email_recipients__email_array_required | json }},\n \"subject\": {{ email_subject | json }},\n \"body\": {{ email_body | json }},\n \"reply_to\": {{ shop.customer_email | json }},\n \"from_display_name\": {{ shop.name | json }}\n }\n {% endaction %}\n{% endif %}\n\n{% comment %}\n Increment recent error count for this error\n{% endcomment %}\n\n{% action \"cache\" %}\n {\n \"incr\": {\n \"key\": {{ fingerprint | json }},\n \"ttl\": 600\n }\n }\n{% endaction %}\n",
"subscriptions": [
"mechanic/errors/event",
"mechanic/errors/task",
"mechanic/errors/action"
],
"subscriptions_template": "mechanic/errors/event\nmechanic/errors/task\nmechanic/errors/action",
"tags": [
"Error"
]
"tags": ["Alert", "Error"]
}