Currently, the redactErrors option supports a boolean or string value to control error redaction behavior, typically removing fields like stack and name.
It would be very useful to allow redactErrors to also accept a function, so users can define custom logic for how errors should be redacted before being streamed or serialized. This would provide more flexibility for different use cases, such as removing or preserving certain fields based on the error type or runtime context.
redactErrors: (error) => {
return {
name: error.name,
message: 'custom messsage',
stack: error.stack.replace(/some-regex/, 'some value'),
};
}
Although the library provides a plugins option — an array of transformation functions like the following:
plugins: [
(value) => {
if (value instanceof Error) {
return [
'CustomError',
value.name,
value.message,
value.stack,
];
}
},
]
— this approach does not work for error redaction, because the library internally converts errors to plain objects before the plugins are applied. As a result, the instanceof Error check always fails, making it impossible to target errors reliably through this mechanism.
Supporting functions in redactErrors would address this gap and make it possible to apply targeted logic to actual error instances before they're transformed.
Currently, the
redactErrorsoption supports abooleanorstringvalue to control error redaction behavior, typically removing fields likestackandname.It would be very useful to allow
redactErrorsto also accept a function, so users can define custom logic for how errors should be redacted before being streamed or serialized. This would provide more flexibility for different use cases, such as removing or preserving certain fields based on the error type or runtime context.Although the library provides a plugins option — an array of transformation functions like the following:
— this approach does not work for error redaction, because the library internally converts errors to plain objects before the plugins are applied. As a result, the instanceof Error check always fails, making it impossible to target errors reliably through this mechanism.
Supporting functions in redactErrors would address this gap and make it possible to apply targeted logic to actual error instances before they're transformed.