Skip to content

feat: output the type of object properties in error messages - #224

Merged
alexander-akait merged 1 commit into
mainfrom
claude/filter-errors-quadratic-sibling-dos-1tqe2l
Sep 8, 2026
Merged

feat: output the type of object properties in error messages#224
alexander-akait merged 1 commit into
mainfrom
claude/filter-errors-quadratic-sibling-dos-1tqe2l

Conversation

@alexander-akait

Copy link
Copy Markdown
Member

Closes #42.

The issue asks for two things.

1. The not keyword

Already fixed on main, so this only locks the issue's three examples into snapshots:

schema message
not: { minimum: 3 } should be any non-number | number (should be < 3).
not: { type: "string" } should be any non-string.
not: { enum: [1, 2] } should not be 1 | 2.

2. The type of each property

An error listing the shape of an object gave the property names only, so it said which properties are valid but not what they take:

configuration.v should be an object:
object { foo?, bar? }

The type is now named next to the property, the form asked for in #42:

configuration.v should be an object:
object { foo?: boolean, bar?: integer }

The existing comment on that code (Maybe we should output type of property (foo: string), but it is looks very unreadable) is the real difficulty here, and it is right — naming every type unconditionally takes the longest line webpack's own schema produces from 1360 to 1959 characters. Three rules keep the output readable:

  • Only a short leaf type is named. A union, an object or an array is left out; listing it inline buries the property names it sits with.
  • The constraints a type carries are dropped, so number (should be >= 2) is named number — the error on the property itself states the constraint anyway.
  • The types are dropped entirely once the shape no longer fits in a line. An object with that many properties is hard enough to read by the names alone. Breaking such an object over several lines is the separate issue noted in improve error reporting in some cases #42 (comment), and this leaves it untouched.

Effect on webpack

Validated against webpack's own schemas/WebpackOptions.json over a spread of invalid configurations. Exactly one line of the resulting messages changes, and it gets better:

-      [object { alias, name, onlyModule? }, ...]
+      [object { alias, name: string, onlyModule?: boolean }, ...]

Total output goes from 11024 to 11041 characters and the longest line is unchanged at 1360 — the big objects (stats, resolve, entry) render byte for byte as before.

Tests

Four cases in test/api.test.js covering the issue's example, composite types being left out, the width cap, and the three not examples. 22 existing snapshots move, each towards more information on a line no longer than before, e.g. object { apply: function, … } and object { foo?: string, bar?: number }.

npm test (490 tests, 338 snapshots), npm run lint and npm run build all pass.

🤖 Generated with Claude Code

https://claude.ai/code/session_013wqLmVHkAGBsWQgXknEQCK


Generated by Claude Code

An error listing the shape of an object gave the property names only, so a
message told which properties are valid but not what they take:

    configuration.v should be an object:
    object { foo?, bar? }

The type is now named next to the property:

    configuration.v should be an object:
    object { foo?: boolean, bar?: integer }

A type is only named when it is a short leaf one. A union, an object or an
array is left out, listing it inline buries the property names it sits with,
and the constraints a type carries are dropped, the error on the property
itself states them anyway. The types are dropped entirely once the shape no
longer fits in a line, an object with that many properties is hard enough to
read by the names alone - webpack's own schema renders byte for byte as
before apart from one nested three-property object.

Closes #42

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013wqLmVHkAGBsWQgXknEQCK
@codecov

codecov Bot commented Sep 8, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 96.66%. Comparing base (49bb7ce) to head (6767a1a).
⚠️ Report is 3 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #224      +/-   ##
==========================================
+ Coverage   95.96%   96.66%   +0.69%     
==========================================
  Files           9        9              
  Lines         967      989      +22     
  Branches      393      408      +15     
==========================================
+ Hits          928      956      +28     
+ Misses         35       31       -4     
+ Partials        4        2       -2     
Flag Coverage Δ
integration 96.66% <100.00%> (+0.69%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@alexander-akait
alexander-akait merged commit 4baf113 into main Sep 8, 2026
33 checks passed
@alexander-akait
alexander-akait deleted the claude/filter-errors-quadratic-sibling-dos-1tqe2l branch September 8, 2026 15:28
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.

improve error reporting in some cases

1 participant