ecs-logging-nodejs icon indicating copy to clipboard operation
ecs-logging-nodejs copied to clipboard

change formatError to not set `ecsFields.err` if the given `err` isn't an Error

Open trentm opened this issue 4 years ago • 1 comments

Currently formatError in the helpers package does this:

function formatError (ecsFields, err) {
  if (!(err instanceof Error)) {
    ecsFields.err = err  // <--- this line
    return
  }

I.e. if err is an Error, then it will fill in ecsFields.error. Otherwise it will set ecsFields.err. But "err" isn't a spec'd ECS field, so it shouldn't do that. It should be up to the callers to handle this. This would also better match formatHttpRequest and formatHttpResponse which do not set ecsFields.req or .res if they cannot process the given value.

This will be a breaking change.

trentm avatar Mar 18 '21 20:03 trentm

Note that as of recently #158, the winston formatter is no longer using helpers.formatError() partly for this reason and partly to add other fields: .cause and any enumerable properties on the error.

trentm avatar Oct 25 '23 20:10 trentm