Skip to content

Conversation

@wjones127
Copy link
Contributor

Summary

Encoding errors now include field context to help identify which field caused the error. This is useful for debugging encoding issues in complex schemas.

  • Wraps encoding errors with field name and ID (e.g., failed to encode field outer (id: 0)``)
  • Adds nested field context for struct fields
  • Handles both synchronous (task creation) and asynchronous (task execution) encoding errors

Example error output:

failed to encode field `outer (id: 0)`

Caused by:
  1: failed to encode field `inner (id: 1)`
  2: Invalid user input: Encountered forbidden value 999

🤖 Generated with Claude Code

wjones127 and others added 5 commits January 1, 2026 16:04
- Replace TestEncodingStrategy with ErrorOnFieldEncodingStrategy that
  wraps StructuralEncodingStrategy
- Use nested struct schema (outer.inner) to test field path context
- Update expected error format to include field path
- Remove obsolete TODOs

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <[email protected]>
Add EncodingFailed error variant that wraps encoding errors with the
field name. This helps users identify which field caused an encoding
failure.

Errors are wrapped in both phases:
- Task creation (maybe_encode returns error)
- Task execution (EncodeTask future resolves to error)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <[email protected]>
StructStructuralEncoder now wraps child encoder errors with the child
field name. This enables error messages to show the full field path
for errors in nested struct fields (e.g., "outer" -> "inner").

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <[email protected]>
Error messages now show field IDs alongside names:
"failed to encode field `outer (id: 0)`"

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <[email protected]>
@github-actions github-actions bot added the enhancement New feature or request label Jan 2, 2026
@github-actions
Copy link
Contributor

github-actions bot commented Jan 2, 2026

Code Review

This PR adds field context to encoding errors, which is useful for debugging. The implementation is solid overall.

P1 Issues

  1. Error wrapping adds overhead on every encoding operation (rust/lance-encoding/src/encodings/logical/struct.rs:449-462, rust/lance-file/src/writer.rs:386-398)

    Every encoding task is wrapped in an async block that clones field_desc and adds a .map_err() call, even when no error occurs. For large schemas with many fields and batches, this creates unnecessary allocations and closure overhead on the hot path.

    Consider wrapping only when errors occur, or using a lighter-weight approach like storing field context in thread-local state that gets attached only when an error bubbles up.

  2. Duplicate field_desc formatting (rust/lance-encoding/src/encodings/logical/struct.rs and rust/lance-file/src/writer.rs)

    The pattern format!("{} (id: {})", field_name, field_id) is duplicated in multiple places. Consider adding a helper method like Field::error_context(&self) -> String to centralize this formatting.

Minor Observations

  • The test coverage is good, testing both sync (task creation) and async (task execution) error paths.
  • The EncodingFailed error variant follows existing patterns in the codebase.

@diffray-bot
Copy link

Changes Summary

This PR improves error reporting for encoding failures by wrapping errors with field context (name and ID). Both synchronous encoding errors (during task creation) and asynchronous errors (during task execution) are wrapped with field context, providing better diagnostics for complex schemas with nested structs.

Type: feature

Components Affected: error handling, struct encoding, file writing, field encoder interface

Files Changed
File Summary Change Impact
/tmp/workspace/rust/lance-core/src/error.rs Added new EncodingFailed error variant with a constructor method to wrap encoding errors with field context. ✏️ 🟢
/tmp/workspace/rust/lance-encoding/src/encoder.rs Modified struct encoder creation to capture child field names and IDs for error context reporting. ✏️ 🟢
.../lance-encoding/src/encodings/logical/struct.rs Updated StructStructuralEncoder to store child field metadata and wrap encoding/flushing/finishing tasks with field-aware error handlers. Added unit test for error wrapping. ✏️ 🟡
/tmp/workspace/rust/lance-file/src/writer.rs Updated file writer to wrap encoding tasks with field context. Added two integration tests for both sync and async encoding errors. ✏️ 🟡
Architecture Impact
  • New Patterns: error context wrapping in async code, field metadata passing for error reporting
  • Dependencies: added: FutureExt import in writer.rs for boxed() method
  • Coupling: Increased coupling between encoder implementations and error handling layer through field metadata propagation. The struct encoder now must maintain child field information specifically for error context.
  • Breaking Changes: StructStructuralEncoder::new() signature changed to include child_fields parameter, Callers of StructStructuralEncoder::new() must provide field metadata

Risk Areas: Error wrapping introduces additional allocations for async closures that capture field_desc strings, Breaking change to StructStructuralEncoder::new() requires updates in all callers, Potential for error message duplication if nested wrapping occurs multiple times, The location!() macro is called multiple times per field, creating many location captures with potential overhead

Suggestions
  • Consider documenting the field ID format in error messages for consistency across the codebase
  • The two test cases in writer.rs are well-designed with custom mock encoders, but could benefit from a shared test utility to avoid duplication
  • Consider adding validation that child_fields and children vectors have matching lengths in StructStructuralEncoder::new()

Full review in progress... | Powered by diffray

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

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants