{
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "nodes": [
    {
      "id": "6ea74f53-4751-410c-9731-a2b253b6673c",
      "name": "Error Trigger",
      "type": "n8n-nodes-base.errorTrigger",
      "position": [
        -544,
        -256
      ],
      "parameters": {},
      "typeVersion": 1
    },
    {
      "id": "b5ba806f-9fa2-4287-8b26-091d34e20750",
      "name": "Slack",
      "type": "n8n-nodes-base.slack",
      "position": [
        -96,
        -256
      ],
      "parameters": {
        "text": "={{ $json.message }}",
        "select": "channel",
        "channelId": {
          "__rl": true,
          "mode": "name",
          "value": "#alerts-n8n-workflows"
        },
        "otherOptions": {}
      },
      "credentials": {
        "slackApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 2.1
    },
    {
      "id": "08d30ea9-049c-4b5e-bce1-488bea5f1cc4",
      "name": "Set message",
      "type": "n8n-nodes-base.set",
      "position": [
        -304,
        -256
      ],
      "parameters": {
        "values": {
          "string": [
            {
              "name": "message",
              "value": "=:warning: [prod] workflow `{{$json[\"workflow\"][\"name\"]}}` failed to run! &lt;{{ $json.execution.url }}|execution&gt;\n\nerror message from node: {{ $json.execution.lastNodeExecuted }}\n {{ $json.execution.error.message }}"
            }
          ]
        },
        "options": {},
        "keepOnlySet": true
      },
      "typeVersion": 1
    },
    {
      "id": "211af477-e53e-47da-9f85-e0af1f1fe1e1",
      "name": "Append row in sheet",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        -96,
        -16
      ],
      "parameters": {
        "columns": {
          "value": {
            "url": "{{ $json.execution.url }}",
            "node": "{{ $json.execution.lastNodeExecuted }}",
            "workflow": "{{$json[\"workflow\"][\"name\"]}}",
            "error message": "{{ $json.execution.error.message }}"
          },
          "schema": [
            {
              "id": "workflow",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "workflow",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "url",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "url",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "node",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "node",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "error message",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "error message",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            }
          ],
          "mappingMode": "defineBelow",
          "matchingColumns": [],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {},
        "operation": "append",
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": "gid=0",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/16NKSpoO7Ib5cKbWsTtlrcod8a_0P6TBUivf-E9E-i9U/edit#gid=0",
          "cachedResultName": "Sheet1"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "16NKSpoO7Ib5cKbWsTtlrcod8a_0P6TBUivf-E9E-i9U",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/16NKSpoO7Ib5cKbWsTtlrcod8a_0P6TBUivf-E9E-i9U/edit?usp=drivesdk",
          "cachedResultName": "workflow error logs"
        }
      },
      "credentials": {
        "googleSheetsOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4.7
    },
    {
      "id": "01a479c2-d204-46d1-b9ff-de49bc3f937b",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1200,
        -368
      ],
      "parameters": {
        "width": 576,
        "height": 416,
        "content": "## n8n Workflow Error Logger\n### How it works\n1. This workflow activates automatically when another n8n workflow fails.\n2. It captures essential error details, including the failing workflow's name, execution link, and the specific error message\n3. A summary message is prepared with these details.\n4. The error summary is immediately posted to a designated Slack channel.\n5. Concurrently, the full error details are appended as a new row in a specified Google Sheet for record-keeping and analysis.\n\n### Setup\n- [ ] Connect your Slack account.\n- [ ] Select the Slack channel where error alerts should be sent (e.g., `#alerts-n8n-workflows`).\n- [ ] Connect your Google Sheets account.\n- [ ] Select the Google Sheet and worksheet for logging workflow errors.\n- [ ] Activate this workflow to start monitoring for errors."
      },
      "typeVersion": 1
    },
    {
      "id": "2b432ca2-7095-4dd8-8785-691d560b80f3",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -560,
        -320
      ],
      "parameters": {
        "color": 7,
        "width": 400,
        "height": 208,
        "content": "## identify error"
      },
      "typeVersion": 1
    },
    {
      "id": "06ae8bcc-2c77-422d-8cc5-becb0b9b3fe1",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -144,
        -320
      ],
      "parameters": {
        "color": 7,
        "height": 464,
        "content": "## log error"
      },
      "typeVersion": 1
    }
  ],
  "connections": {
    "Slack": {
      "main": [
        []
      ]
    },
    "Set message": {
      "main": [
        [
          {
            "node": "Slack",
            "type": "main",
            "index": 0
          },
          {
            "node": "Append row in sheet",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Error Trigger": {
      "main": [
        [
          {
            "node": "Set message",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}