Skip to content

fix: include column and row context in bulk load errors - #1827

Merged
arthurschreiber merged 3 commits into
tediousjs:masterfrom
Ananya2:fix/bulk-load-validation-error-context
Nov 16, 2026
Merged

arthurschreiber merged 3 commits into
tediousjs:masterfrom
Ananya2:fix/bulk-load-validation-error-context

Conversation

@Ananya2

@Ananya2 Ananya2 commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

Bulk-load errors did not identify which column or row contained an invalid value. With many columns and rows, a generic validation error such as Invalid date. made the failing input difficult to locate.

Changes

  • Wrap row-value validation failures in an InputError that identifies the column and zero-based row index. Preserve the original validator error as cause.
  • Wrap row-value serialization failures with the same column and row context, using a distinct message so serialization errors are not mislabeled as validation failures.
  • Reject rows that are not arrays or objects with an InputError identifying the zero-based row index.
  • Include property access in validation error handling so errors from throwing getters also receive column and row context.

For example, a validation error is now reported as:

InputError: Column 'createdAt' could not be validated at row index 2
  [cause]: TypeError: Invalid date.

A serialization error is reported as:

InputError: Column 'value' could not be serialized at row index 0
  [cause]: TypeError: Binary value of 5 bytes exceeds the declared length of 3.

Compatibility

  • Bulk-load validation messages change from the validator's message (for example, Invalid date.) to Column '<name>' could not be validated at row index N.
  • Row-value serialization messages gain the suffix at row index N; code matching the previous exact message may need updating.
  • The original error is available through err.cause. InputError extends TypeError, so instanceof TypeError checks continue to work. Validator failures that were previously other error classes, such as SyntaxError, are now surfaced as an InputError with that original error as cause.
  • Rows that are neither arrays nor objects, including strings and numbers, now fail instead of being treated as rows of NULL values.
  • The wrapper message does not include the rejected value. The original validator error is passed through unchanged as cause, and its message may contain the value.
  • No new public API.

Tests

  • Unit tests cover array and object rows, including cases where an object's input property name differs from the database column name.
  • Unit tests verify wrapper messages and preserved causes, throwing row getters, non-TypeError validator failures, and invalid primitive rows.
  • Unit and integration expectations for oversized Binary serialization errors account for the row-index suffix.
  • Streaming validation tests verify that the wrapped error and original cause are reported.

Breaking change note

Bulk-load validation and row-value serialization errors now have different top-level messages and are wrapped in InputError; consumers matching exact error messages may need to update. The original error is available in err.cause. Rows that are not arrays or objects now throw instead of being loaded as NULL rows.

@codecov

codecov Bot commented Oct 13, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 83.90%. Comparing base (b41a75e) to head (6eb4b39).

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1827      +/-   ##
==========================================
+ Coverage   83.88%   83.90%   +0.02%     
==========================================
  Files          96       96              
  Lines        4728     4735       +7     
  Branches      888      889       +1     
==========================================
+ Hits         3966     3973       +7     
  Misses        509      509              
  Partials      253      253              

☔ 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.

@arthurschreiber arthurschreiber left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, this follows the existing InputError convention nicely. The main suggestion is to add the row index, as the TVP path already does, since the column name alone doesn't help much on large loads. A null row still fails with a context-free error, and one integration test lost its cause check. The rest are small test and style points.


Generated by Claude Code

Comment thread src/bulk-load-payload.ts Resolved
Comment thread src/bulk-load-payload.ts Resolved
Comment thread test/integration/bulk-load-test.ts Resolved
Comment thread test/unit/bulk-load-test.ts Resolved
Comment thread src/bulk-load-payload.ts Resolved
Comment thread test/unit/bulk-load-test.ts Resolved

@cheenamalhotra cheenamalhotra left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few things worth addressing:

  1. Breaking change for error matching. Bulk load validation errors now have a different message (Column 'x' could not be validated at row index N instead of e.g. Invalid date.), and serialization errors gain at row index N. Code matching on err.message will break. Since release notes come from the squash commit, consider adding a footer so it's flagged:

    BREAKING CHANGE: Bulk load validation and serialization errors are now
    `InputError`s with messages like "Column 'x' could not be validated at
    row index N". The original error is in `err.cause`. Rows that are not
    arrays or objects now throw instead of loading as NULLs.
    

    @arthurschreiber — would you treat this as breaking, or just call it out in the notes?

  2. Rows that aren't objects now fail. A string or number row used to load silently as all NULLs. Good fix, but it's a behavior change. Please add a test with a primitive row (e.g. 'abc', 42).

  3. Sensitive value claim. writeDecimal (src/data-types/decimal-common.ts) throws Value ${value} is out of range..., which ends up in cause. Either drop the value from that message or adjust the claim in the description.

  4. Description is out of date. It doesn't mention the row index or the new row check. Please update the examples and the Compatibility section.

@arthurschreiber arthurschreiber left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for addressing the earlier round. Two things block merging now:

  • The branch conflicts with master in test/unit/bulk-load-test.ts.
  • Once that conflict is resolved, a unit test added in #1817 fails because the "could not be serialized" message now has the row index suffix (details inline).

The description is also out of date. It still shows the messages without at row index N, and it doesn't mention the new row check or the change to the serialization message. Could you update it along with the rebase?

The remaining inline comments are about the row guard, the "without exposing the value" test, and the single try block.


Generated by Claude Code

Comment thread src/bulk-load-payload.ts Resolved
Comment thread src/bulk-load-payload.ts Resolved
Comment thread src/bulk-load-payload.ts Resolved
Comment thread test/unit/bulk-load-test.ts Resolved
@Ananya2
Ananya2 force-pushed the fix/bulk-load-validation-error-context branch from c40450b to 6eb4b39 Compare November 16, 2026 04:19
@Ananya2 Ananya2 changed the title fix: include column context in bulk load validation errors fix: include column and row context in bulk load errors Nov 16, 2026
@arthurschreiber
arthurschreiber merged commit f759e3e into tediousjs:master Nov 16, 2026
59 of 60 checks passed
@github-actions

Copy link
Copy Markdown
Contributor

🎉 This PR is included in version 20.3.10 🎉

The release is available on:

Your semantic-release bot 📦🚀

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.

3 participants