Skip to content

fix: keep a Date in log metadata instead of writing {} (2.2.1) - #153

Merged
robdmoore merged 2 commits into
mainfrom
fix/date-metadata
Oct 16, 2026
Merged

robdmoore merged 2 commits into
mainfrom
fix/date-metadata

Conversation

@cuzzlor

@cuzzlor cuzzlor commented Oct 16, 2026 •

Copy link
Copy Markdown
Collaborator

Fixes #152.

What

From 2.0.0 to 2.2.0, any Date in log metadata reached every transport as {}. serializeErrorFormat runs first at the logger level, and its metadata walk rebuilds every object from Object.keys; a Date has no own enumerable keys. 1.x left metadata alone and the JSON step wrote the ISO string.

logger.info('db query', { parameters: [new Date('2026-01-02T03:04:05Z'), 1] })
// 2.2.0: { parameters: [{}, 1] }
// 2.2.1: { parameters: [Date, 1] }  → JSON: ["2026-01-02T03:04:05.000Z",1]

How

  • Metadata walk (serializeErrorFormat): a value that defines toJSON — Date, URL, a date-library instance — is passed through as the same reference, as 1.x did. A transport receives the Date; the console's format.json, flatten and any other JSON step write its ISO string.
  • Error serializer (serializeError): output must be plain, so a toJSON value on an error is replaced by what it returns — ISO string, null for an invalid Date, href for a URL. When toJSON throws or returns the value itself, the own-keys walk runs as before.
  • An error is never asked for its toJSON, so an error class that defines one (an AxiosError, say) is still captured whole — name, message, stack and its own fields — rather than as whatever its toJSON chooses to show.
  • The helper lives in an internal module that index.ts does not re-export, so the public API is unchanged.

Also: unblocks CI and publishing

Advisories published since 2.2.0 make npm run audit fail, and both the PR workflow and publish.yml run it first, so main could not publish anything. All nine are in dev tooling. A non-forcing npm audit fix clears the lockfile-only ones; vitest / @vitest/coverage-v8 move 4.1.4 → 4.1.12. The fflate fix (0.8.2 → 0.8.3) breaks attw 0.18.2's tarball parsing (Cannot read properties of undefined (reading 'filename')), so @arethetypeswrong/cli moves to 0.18.5, which targets fflate 0.8.3.

Version

2.2.1 — patch. It restores 1.x behaviour; no output that was correct in 2.2.0 changes. Publishing happens on merge (publish.yml). This should merge before the 2.3.0 OTel PR, which is stacked on this branch.

Test plan

  • npm run build — lint, tsc, rollup, attw --pack, CJS smoke test
  • npm test — 154 tests. The 8 new tests that exercise the bug fail against main's source and pass here; 3 guard tests (an error with toJSON in the format and in the serializer, a toJSON that throws) pass on both
  • Found downstream: MakerXStudio/MakerBOS#1612 logs TypeORM timestamptz parameters and carries a workaround that this makes removable

From 2.0.0 the logger-level error format rebuilt every metadata object
from its own enumerable keys, and a Date has none, so every Date reached
every transport as `{}` — a TypeORM query parameter, a timestamp field,
anything. 1.x left them for the JSON step, which writes the ISO string.

A value that defines `toJSON` is now passed through the metadata walk as
the same reference, as 1.x did. Inside a serialized error, where the
output must be plain, it is replaced by what its `toJSON` returns: a Date
becomes its ISO string, an invalid one `null`, a URL its href. An error
is never asked for its `toJSON`, so an AxiosError-style error is still
captured whole.

Fixes #152
Advisories published since 2.2.0 fail `npm run audit`, which both the PR
workflow and the publish workflow run before anything else, so no release
could ship. All are in dev tooling: brace-expansion, fast-uri, fflate,
shell-quote, source-map-js, @humanfs/node (lockfile only), and vitest /
@vitest/coverage-v8 4.1.4 → 4.1.12.

The fflate fix (0.8.2 → 0.8.3) changes how its streaming gunzip emits
chunks and breaks attw 0.18.2's tarball parsing, so attw moves to 0.18.5,
which targets fflate 0.8.3.
@robdmoore
robdmoore merged commit e0caec9 into main Oct 16, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

serializeErrorFormat turns a Date in log metadata into {}

2 participants