Workflow stops on error (error - expected scenario). Any methods to display the error as a message

Hi ,

I am working on a workflow to enter some data from my file to questdb. I have a situation where one row of data in my file doesn’t match with the datatype of the table’s column (table created in questdb). In such a situation , the workflow stops execution (I haven’t given the option to continue on fail). My requirement is to display a message stating error has occured (if any) or successful completion ( if no error). Since the workflow stops it’s execution after the node fails, how can I accomplish this?. Is there any way I can identify whether an error has acquired and display a message accordingly.

This is how the workflow looks like.

Thank you

My first thought would be to enable the Continue On Fail setting on the QuestDB node:

You could then check after the QuestDB node whether all items were processed successfully or respond with an error if not.

I tthank you very much for the quick response

. I have already done that. Like the description says, it passes on the input data from previous node. I want to add a node to show whether data addition to database was successful or not and continue with more steps if successful. , In my case, it is possible to show the success message (using set node) when the node gets executed and go ahead with the later steps. . But what about the case when data entry is not possible? I have to display the message and stop execution. So, the displaying message once failure occurs is important. Any way to achieve this? How can I check whether a previous node was executed or not? Also, is there a way to use this information in the workflow

I have to display the message and stop execution. So, the displaying message once failure occurs is important. Any way to achieve this?

If you want to immediately stop the execution on error, you wouldn’t be able to use the Continue On Fail setting suggested in my previous message. In this case the workflow would throw an error (which you could further handle with an error workflow), but it’s not possible to return a custom error in this case. So you would need to implement the “display the message” part in whatever application is calling the webhook.

How can I check whether a previous node was executed or not?

Execution happens sequentially, so whenever a node runs it means the previous node finished the execution.

As for error handling: If you do use the aforementioned Continue On Fail setting, you could run use the Execute Query operation instead of Insert. The QuestDB node only returns the failed items in this case and you could build your error message around this.

This example will try to insert 3 items, the middle one will fail and is returned by the final node:

Example Workflow
{
  "nodes": [
    {
      "parameters": {},
      "name": "Start",
      "type": "n8n-nodes-base.start",
      "typeVersion": 1,
      "position": [
        250,
        300
      ]
    },
    {
      "parameters": {
        "operation": "executeQuery",
        "query": "CREATE TABLE IF NOT EXISTS foo (text string, number int, created timestamp)",
        "additionalFields": {}
      },
      "name": "Set Up Table",
      "type": "n8n-nodes-base.questDb",
      "typeVersion": 1,
      "position": [
        450,
        300
      ],
      "alwaysOutputData": true,
      "credentials": {
        "questDb": {
          "id": "15",
          "name": "QuestDB account"
        }
      }
    },
    {
      "parameters": {
        "functionCode": "return [{\n  json: {\n    text: 'Foo',\n    number: 1,\n    created: new Date().toISOString()\n  }\n}, {\n  json: {\n    text: 'Bar',\n    number: 'Bar',\n    created: new Date().toISOString()\n  }\n}, {\n  json: {\n    text: 'Baz',\n    number: 3,\n    created: new Date().toISOString()\n  }\n}]"
      },
      "name": "Set Sample Data",
      "type": "n8n-nodes-base.function",
      "typeVersion": 1,
      "position": [
        650,
        300
      ]
    },
    {
      "parameters": {
        "operation": "executeQuery",
        "query": "INSERT INTO foo(text, number, created) VALUES ($1, $2, $3);",
        "additionalFields": {
          "queryParams": "text, number, created"
        }
      },
      "name": "Insert Data",
      "type": "n8n-nodes-base.questDb",
      "typeVersion": 1,
      "position": [
        850,
        300
      ],
      "alwaysOutputData": false,
      "notesInFlow": true,
      "credentials": {
        "questDb": {
          "id": "15",
          "name": "QuestDB account"
        }
      },
      "continueOnFail": true,
      "notes": "Only returns items with an error!"
    }
  ],
  "connections": {
    "Start": {
      "main": [
        [
          {
            "node": "Set Up Table",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Set Up Table": {
      "main": [
        [
          {
            "node": "Set Sample Data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Set Sample Data": {
      "main": [
        [
          {
            "node": "Insert Data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}

I hope this provides some indicators on how you could possibly approach your problem!

1 Like

Hi,

I tried by using the query instead of insert and it solved the problem. Thank you very much. Now I can carry on with seperate steps for the cases of success and failure.

1 Like

Awesome, glad to hear and thanks a lot for confirming!

1 Like