Skip to content

Feature request: improve error handling #1647

Closed
@dreamorosi

Description

@dreamorosi

Use case

Currently some of the errors in the Batch Processing utility are either generic or hard to parse/read. We could improve on them considering that we encourage JSON-structured logging.

Solution/User Experience

Currently the error thrown when the full batch fails processing looks like this:

{
    "errorType": "Error",
    "errorMessage": "\nAll records failed processing. 1 individual errors logged separately below.\n,Failed to process record, 3\n",
    "msg": "All records failed processing. 1 individual errors logged separately below.",
    "childErrors": [
        {
            "errorType": "Error",
            "errorMessage": "Failed to process record, 3",
            "stack": [
                "Error: Failed to process record, 3",
                "    at BatchProcessor2.recordHandler [as handler] (/var/task/index.js:416:11)",
                "    at BatchProcessor2.processRecord (/var/task/index.js:250:31)",
                "    at BatchProcessor2.process (/var/task/index.js:131:38)",
                "    at processPartialResponse2 (/var/task/index.js:299:18)",
                "    at Runtime.handler (/var/task/index.js:421:50)",
                "    at Runtime.handleOnceNonStreaming (file:///var/runtime/index.mjs:1083:29)"
            ]
        }
    ],
    "stack": [
        "Error: ",
        "All records failed processing. 1 individual errors logged separately below.",
        ",Failed to process record, 3",
        "",
        "    at BatchProcessor2.clean (/var/task/index.js:179:17)",
        "    at BatchProcessor2.process (/var/task/index.js:133:14)",
        "    at processPartialResponse2 (/var/task/index.js:299:18)",
        "    at Runtime.handler (/var/task/index.js:421:50)",
        "    at Runtime.handleOnceNonStreaming (file:///var/runtime/index.mjs:1083:29)"
    ]
}

The error message could use some improvement and be rendered instead like:

{
    "errorType": "FullBatchFailureError",
    "errorMessage": "All records failed processing. See individual errors below.",
    "name": "FullBatchFailureError",
    "recordErrors": [
        {
            "errorType": "Error",
            "errorMessage": "Failed to process record, 2",
            "stack": [
                "Error: Failed to process record, 2",
                "    at BatchProcessor2.recordHandler [as handler] (/var/task/index.js:421:11)",
                "    at BatchProcessor2.processRecord (/var/task/index.js:256:31)",
                "    at BatchProcessor2.process (/var/task/index.js:137:38)",
                "    at processPartialResponse2 (/var/task/index.js:304:18)",
                "    at Runtime.handler (/var/task/index.js:426:50)",
                "    at Runtime.handleOnceNonStreaming (file:///var/runtime/index.mjs:1083:29)"
            ]
        },
        {
            "errorType": "Error",
            "errorMessage": "Failed to process record, 3",
            "stack": [
                "Error: Failed to process record, 3",
                "    at BatchProcessor2.recordHandler [as handler] (/var/task/index.js:421:11)",
                "    at BatchProcessor2.processRecord (/var/task/index.js:256:31)",
                "    at BatchProcessor2.process (/var/task/index.js:137:38)",
                "    at processPartialResponse2 (/var/task/index.js:304:18)",
                "    at Runtime.handler (/var/task/index.js:426:50)",
                "    at Runtime.handleOnceNonStreaming (file:///var/runtime/index.mjs:1083:29)"
            ]
        },
        {
            "errorType": "Error",
            "errorMessage": "Failed to process record, 4",
            "stack": [
                "Error: Failed to process record, 4",
                "    at BatchProcessor2.recordHandler [as handler] (/var/task/index.js:421:11)",
                "    at BatchProcessor2.processRecord (/var/task/index.js:256:31)",
                "    at BatchProcessor2.process (/var/task/index.js:137:38)",
                "    at processPartialResponse2 (/var/task/index.js:304:18)",
                "    at Runtime.handler (/var/task/index.js:426:50)",
                "    at Runtime.handleOnceNonStreaming (file:///var/runtime/index.mjs:1083:29)"
            ]
        }
    ],
    "stack": [
        "FullBatchFailureError: All records failed processing. See individual errors below.",
        "    at BatchProcessor2.clean (/var/task/index.js:185:17)",
        "    at BatchProcessor2.process (/var/task/index.js:139:14)",
        "    at processPartialResponse2 (/var/task/index.js:304:18)",
        "    at Runtime.handler (/var/task/index.js:426:50)",
        "    at Runtime.handleOnceNonStreaming (file:///var/runtime/index.mjs:1083:29)"
    ]
}

Likewise, other errors thrown when the utility receives a wrong type, or short-circuits the processing of a FIFO SQS batch, can be improved either in their implementation or output.

Alternative solutions

No response

Acknowledgment

Future readers

Please react with 👍 and your use case to help us understand customer demand.

Metadata

Metadata

Assignees

Labels

batchThis item relates to the Batch Processing UtilitycompletedThis item is complete and has been merged/shippedfeature-requestThis item refers to a feature request for an existing or new utility

Type

No type

Projects

Status

Shipped

Relationships

None yet

Development

No branches or pull requests

Issue actions