Skip to content

Include byte offset in decode errors#49

Merged
agis merged 3 commits into
mainfrom
GH22-byte-offset-in-errors
Mar 17, 2026
Merged

Include byte offset in decode errors#49
agis merged 3 commits into
mainfrom
GH22-byte-offset-in-errors

Conversation

@agis

@agis agis commented Mar 16, 2026

Copy link
Copy Markdown
Owner

We introduce OffsetReader, which is a thin wrapper around an std::io::Read and stores the amount of bytes consumed so far. We then use that information to make DecodeModuleError more useful, by including the offset at which a decoding error occurred.

Also, executed cargo fmt in the process.

Resolves #22

We introduce `OffsetReader`, which is a thin wrapper around an
`std::io::Read` and stores the amount of bytes consumed so far. We then
use that information to make `DecodeModuleError` more useful, by
including the offset at which a decoding error occurred.

Also, executed `cargo fmt` in the process.

Resolves #22
Copilot AI review requested due to automatic review settings March 16, 2026 20:30

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR enhances decode error reporting by tracking the byte position of the input stream during module decoding and attaching that offset to top-level decode errors (resolving #22). It also updates tests and public re-exports to account for the new error shape, alongside formatting/import reordering from cargo fmt.

Changes:

  • Introduce an internal OffsetReader wrapper to track bytes consumed during decode_module.
  • Replace the previous DecodeModuleError enum with a struct that includes { offset, source }, where source is a new DecodeModuleErrorKind enum.
  • Update tests and error-type re-exports to match on err.source (the kind) rather than the old top-level enum variants.

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
src/decode/module.rs Adds OffsetReader and restructures module decode errors to include byte offsets.
src/decode/mod.rs Re-exports DecodeModuleErrorKind alongside DecodeModuleError.
src/decode_errors.rs Re-exports DecodeModuleErrorKind for consumers.
tests/tests.rs Updates pattern matches to use err.source / DecodeModuleErrorKind.
tests/error_types.rs Updates extensive error-shape assertions to use err.source / DecodeModuleErrorKind.
src/decode/helpers.rs Import reordering from formatting.
src/decode/types/limits.rs Import reordering from formatting.
src/decode/types/heaptype.rs Import reordering from formatting.
src/decode/types/globaltype.rs Import reordering from formatting.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

Comment thread src/decode/module.rs
Comment thread src/decode/module.rs
Comment thread src/decode/module.rs
@agis agis merged commit cef6489 into main Mar 17, 2026
4 checks 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.

Input byte offsets in errors

2 participants