reduceContext.errors
Property Description |
Holds serialized errors that were thrown during previous attempts to execute the reduce function on the current key and its values. This iterator may also hold the For an overview of events that can cause the map function to be invoked multiple times for a key-value pair, see System Response After a Map/Reduce Interruption. |
Type |
iterator |
Since |
2018.1 |
Members
Member |
Type |
Required/Optional |
Description |
---|---|---|---|
iterator().each(parameters) |
function |
required |
Executes one time for each error. |
parameters
Member |
Type |
Required/Optional |
Description |
---|---|---|---|
iteratorFunction(key, error, executionNo) See also functionParameters. |
function |
required |
Provides logic to be executed during each iteration. |
functionParameters
Parameter |
Type |
Required/Optional |
Description |
---|---|---|---|
key |
string |
optional |
Represents the key-value pair that the reduce function was attempting to process when the error occurred. |
error |
string |
optional |
A serialization of the error thrown. |
executionNo |
number |
optional |
Indicates whether the error occurred during the first or a subsequent attempt to process the key. |
Syntax
The following snippets shows three ways you could use this iterator.
This code is not a functional example. For a complete script sample, see Map/Reduce Script Samples.
//Add additional code
...
// Create a log entry showing each full serialized error, and the corresponding key.
context.errors.iterator().each(function (key, error, executionNo){
log.error({
title: 'Reduce error for key: ' + key + ', execution no ' + executionNo,
details: error
});
return true;
});
// Log only the name and description of each error thrown.
context.errors.iterator().each(function (key, error, executionNo){
var errorObject = JSON.parse(error);
log.error({
title: 'Reduce error for key ' + key + ', execution no. ' + executionNo,
details: errorObject.name + ': ' + errorObject.message
});
return true;
});
// Calculate and log the number of errors encountered.
var errorCount = 0;
context.errors.iterator().each(function() {
errorCount ++;
return true;
});
log.audit ({
title: 'Errors for reduce key: ' + context.key,
details: 'Total number of errors: ' + errorCount
});