Skip to content

feat: include error.id and error.code in formatError, @elastic/ecs-helpers@2.2.0#233

Open
edosrecki wants to merge 1 commit into
elastic:mainfrom
edosrecki:edosrecki/format-error-include-id-code
Open

feat: include error.id and error.code in formatError, @elastic/ecs-helpers@2.2.0#233
edosrecki wants to merge 1 commit into
elastic:mainfrom
edosrecki:edosrecki/format-error-include-id-code

Conversation

@edosrecki

@edosrecki edosrecki commented Jul 3, 2026

Copy link
Copy Markdown

Why?

The ECS error field set includes error.id and error.code alongside error.type, error.message, and error.stack_trace. formatError() was only emitting the latter three, so any id/code properties on the source Error (for example Node system errors with err.code === 'ENOENT') were silently dropped.

How?

Copy err.code and err.id onto the emitted error object when they are defined on the source Error, guarded so plain errors keep the same minimal shape as before. Values pass through as-is — matching the existing behavior in ecs-winston-format, which already surfaces err.code via Object.assign({}, err).

Picked up automatically by @elastic/ecs-pino-format via its call to formatError. ecs-winston-format and ecs-morgan-format do not call formatError and are unaffected. Bumped @elastic/ecs-helpers to v2.2.0 and added a matching CHANGELOG entry.

…lpers@2.2.0

The ECS error field set includes `error.id` and `error.code` alongside
`error.type`, `error.message`, and `error.stack_trace`. `formatError()`
was only emitting the latter three, so any `id`/`code` properties on the
source `Error` (for example Node system errors with `err.code === 'ENOENT'`)
were silently dropped.

Copy these fields through when they are defined on the source error,
guarded so plain errors keep the same minimal shape as before. Values
are passed through as-is, matching the existing behavior in
ecs-winston-format (which already surfaces `err.code` via
`Object.assign({}, err)`).

Picked up automatically by @elastic/ecs-pino-format via its call to
formatError. ecs-winston-format and ecs-morgan-format do not call
formatError and are unaffected.

See: https://www.elastic.co/docs/reference/ecs/ecs-error
@github-actions

github-actions Bot commented Jul 3, 2026

Copy link
Copy Markdown

🤖 GitHub comments

Just comment with:

  • run docs-build : Re-trigger the docs validation. (use unformatted text in the comment!)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant