Skip to content

fix: omitNilFormat preserves info on objects with numeric length#146

Merged
cuzzlor merged 1 commit intomainfrom
fix/omit-nil-format-array-like-bug
May 6, 2026
Merged

fix: omitNilFormat preserves info on objects with numeric length#146
cuzzlor merged 1 commit intomainfrom
fix/omit-nil-format-array-like-bug

Conversation

@cuzzlor
Copy link
Copy Markdown
Collaborator

@cuzzlor cuzzlor commented May 6, 2026

Summary

  • omitNilFormat was switched from lodash to es-toolkit/compat in v2. Unlike lodash, es-toolkit/compat's omitBy treats any object with a numeric length property as array-like — it iterates 0..length-1, returns {}, and drops winston's LEVEL/MESSAGE symbols. This breaks downstream formats like colorize whenever a pg error is splatted into the log call (pg errors carry a numeric length).
  • Replace the omitBy call with a hand-rolled loop over Object.keys + Object.getOwnPropertySymbols — equivalent to the original lodash behaviour and immune to the array-like heuristic.
  • Bump to 2.0.1.

Refs toss/es-toolkit#1706.

Test plan

  • New regression spec (src/omit-nil-format.spec.ts) feeds an info object with a numeric length property and asserts Symbol.for('level') / Symbol.for('message') survive
  • npx vitest run src/omit-nil-format.spec.ts — 3/3 pass
  • npx tsc -p tsconfig.json — clean
  • npx eslint src/omit-nil-format.ts src/omit-nil-format.spec.ts — clean

🤖 Generated with Claude Code

Switch omitNilFormat from es-toolkit/compat's omitBy to a hand-rolled
loop. es-toolkit/compat's omitBy treats any object with a numeric
`length` (e.g. a pg error spread via splat) as array-like — it returns
{} and drops winston's LEVEL/MESSAGE symbols, breaking downstream
formats like colorize. Bump to 2.0.1.

Refs toss/es-toolkit#1706.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@cuzzlor cuzzlor merged commit 9c64c43 into main May 6, 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.

1 participant