# How to log/capture errors and create an error report

**URL:** https://community.synatic.com/t/how-to-log-capture-errors-and-create-an-error-report/349
**Category:** Flows
**Tags:** error-reporting
**Created:** [May 10, 2023, 7:14am UTC](https://community.synatic.com/t/how-to-log-capture-errors-and-create-an-error-report/349 "2023-05-10T07:14:22Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![Faizel](https://yyz2.discourse-cdn.com/flex032/user_avatar/community.synatic.com/faizel/32/918_2.png) [@Faizel](https://community.synatic.com/u/Faizel)
#### Post date: [May 10, 2023, 7:14am UTC](https://community.synatic.com/t/how-to-log-capture-errors-and-create-an-error-report/349/1 "2023-05-10T07:14:22Z")

</div>

If you require to **log/capture errors and create an error report** , please follow the instructions below:

Illustrated in the image below is an example of a flow that has a Record Generator as a source step and it throws/returns an error from the Calculator step. The error and record gets stored in an event buffer that can be queried.

 ![image](https://canada1.discourse-cdn.com/flex032/uploads/synatic/original/2X/9/92dd1ece6c0c3a303be6d79f1ba2295061e44284.png)

The example in the Calculator step as shown in the image below will throw/return as an error.

 ![image](https://canada1.discourse-cdn.com/flex032/uploads/synatic/original/2X/d/d4dccfc1193ccab7617f5ae64cfcdc79f6138e4a.png)

There are two types of Event Buffers that can be used to store the errors and records. They are the **Record Event Buffer step and the Run Event Buffer step.**

1. To **add an Event Buffer step** , click on the last plus icon (+) at the end of the flow as highlighted in the below image. Select the Record/Run Event Buffer and add the buffer.

![image](https://canada1.discourse-cdn.com/flex032/uploads/synatic/original/2X/b/b892308bb1610f9282532318bd5e603f464db667.png)

**RecordEvent Buffer step:**

This buffer stores the **record information** for a processed run. The data gets stored on [MongoDB](https://www.techtarget.com/searchdatamanagement/definition/MongoDB).

Select/tick the required event/s to store in the buffer, then select an existing buffer or create a new buffer as shown in the page below. The maximum number of records that can be stored in the buffer is set to 100 as a default and it can be increased.

**NB: Ticking Clean Record will remove the record details.**

 ![image](https://canada1.discourse-cdn.com/flex032/uploads/synatic/original/2X/4/449e1542d2c88264524c0ab1b029d5daa2503384.png)

The below payload shows the **fields that get stored in the Record Event Buffer**.

```auto
[
    {
        "_id": "645b42d964ab55a91ae85659",
        "recordType": "record",
        "record": {
            "Id": 323,
            "Category": "Fish",
            "Food Item": "Anchovies, canned in oil, drained solids",
            "Measure": 2,
            "Calories": 17,
            "Protein": 2,
            "Fat": 1,
            "Carbs": 0,
            "Fibre": null
        },
        "runId": "645b42d9d9873",
        "type": "record",
        "status": {
            "current": "Error",
            "date": "2023-05-10T07:08:09.589Z"
        },
        "stepId": "a3ec9b22-dba6-4196-aef8-02d4771e7c6f",
        "error": {
            "message": "Error running calculation",
            "statusCode": 400,
            "error": "This is a sample error",
            "errorMessage": null
        },
        "flowId": "6454d25278f3",
        "flowVersion": null,
        "parameters": null,
        "flowName": "demo-docfusion--error-logging",
        "_dateUpdated": "2023-05-10T07:08:09.595Z"
    }
]

```

**RunEvent Buffer step:**

This buffer stores the **run information** of a processed run.

Select/tick the required event/s to store in the buffer, then select an existing buffer or create a new buffer as illustrated in the below image.

 ![image](https://canada1.discourse-cdn.com/flex032/uploads/synatic/original/2X/e/e0cd81c430173e08f0fa231ece28bda28ca0d4ce.png)

The below payload shows the **fields that get stored in the Run Event Buffer**.

```auto
[
    {
        "_id": "645b4258c2c55011daf4937c",
        "event": "Completed with Errors",
        "data": {
            "run": {
                "_id": "645b4258d9873c3db2b7ec8f",
                "batchId": null,
                "processId": null
            },
            "flow": {
                "_id": "6459025bd9873c",
                "name": "error-logging",
                "title": "Demo> Error Logging-Run"
            },
            "solution": {
                "_id": "6437c2760171",
                "name": "usersolutions",
                "title": "UserSolutions"
            },
            "headers": [],
            "footers": [],
            "parameters": {},
            "org": {
                "name": "orgname",
                "title": "orgname"
            },
            "error": null,
            "stats": {
                "processingDates": {
                    "created": "2023-05-10T07:06:00.839Z",
                    "started": "2023-05-10T07:06:00.840Z",
                    "actions": "2023-05-10T07:06:00.847Z",
                    "completed": null
                },
                "recordStats": {
                    "errors": 1,
                    "total": 1,
                    "completed": 0,
                    "headers": 0,
                    "footers": 0,
                    "skipped": 0
                }
            }
        },
        "type": "run",
        "runId": "645b4258d9873",
        "flowId": "6459025bd987",
        "flowVersion": null,
        "_dateUpdated": "2023-05-10T07:06:00.850Z"
    }
]

```

1. Create a flow to query the buffer and email the error report which is an Excel file.

Illustrated in the below flow is a Buffer Query source step to retrieve the error data from the buffer, create an Excel file and send the file as an email attachment.

 ![image](https://canada1.discourse-cdn.com/flex032/uploads/synatic/original/2X/8/8350a26d57f87cebd559f0ca1fd5d383d51aa370.png)

The Buffer Query source step is used to write a SQL query to return the required fields from the buffer as illustrated in the image below.

**N.B: Each field name in the buffer needs to have an alias field name to ensure that there is no conflict when querying the buffer due to a run’s default field names.**

 ![image](https://canada1.discourse-cdn.com/flex032/uploads/synatic/original/2X/e/e07db87239665d464e89f490cfffe6494085f63f.png)

The below image shows the returned results from the Buffer Query source step.

 ![image](https://canada1.discourse-cdn.com/flex032/uploads/synatic/original/2X/7/766de2ed037f60e7317bb88f06dae945ab9af3c5.png)

An Excel file gets created with the payload and emailed to a recipient using the Email destination step.

 ![image](https://canada1.discourse-cdn.com/flex032/uploads/synatic/original/2X/4/4e126fafb083813d2b9320d73fd6d9a7180ea2ce.png)
