try_catch
Attempts a list of child processors and, if any of them fail, applies a separate list of catch processors to recover from the error.
The processors are applied to each message in order. If any of them fails, the remaining processors are skipped, the message's failure flag is cleared, and the original error is written to metadata under the key set by error_metadata so the catch processors can inspect it. The catch processors then run, letting you log, transform, drop, or otherwise react to failed messages. More information about error handling can be found here.
# Config fields, showing default values
processor:
label: ""
try_catch:
processors: []
catch: []
error_metadata: error
Examples
- Recover from a failure
- Log and drop failures
Attempt to enrich each message, and if the enrichment step fails replace the message with an explanatory payload built from the stored error.
processor:
try_catch:
processors:
- resource: enrich_data
catch:
- mapping: 'root = "failed to process: " + @error.what'
Parse each message as JSON. When parsing fails, log the error and drop the message instead of letting the failure propagate.
processor:
try_catch:
processors:
- mapping: 'root = this.parse_json()'
catch:
- log:
level: ERROR
message: 'Message dropped after failure: ${! @error.what }'
- mapping: 'root = deleted()'
Fields
processors
The list of child processors to attempt on each message. They are applied in the order given, and if any of them fails the remaining processors in the list are skipped and the catch processors run instead.
Type: array
Default: []
catch
The list of processors to apply to a message when one of the processors fails. The message's failure flag is cleared before these run, so they operate on the message as though it had not failed, which is useful for recovering, logging, or dropping failed messages.
Type: array
Default: []
error_metadata
The metadata key under which the original error is stored so that the catch processors can inspect it. The stored value includes details about the failure such as what, name, label, and path.
Type: string
Default: error