Skip to content

fix: Show InputIndexOutOfRange original error - #1101

Open
ItoroD wants to merge 1 commit into
masterfrom
add-outofrange-error
Open

ItoroD wants to merge 1 commit into
masterfrom
add-outofrange-error

Conversation

@ItoroD

@ItoroD ItoroD commented Aug 24, 2026

Copy link
Copy Markdown
Collaborator

Description

Resolves #1096

Notes to the reviewers

IndexOutOfBoundsError is being returned directly with no concatenation from bdk-wallet. See here and the error itself

Documentation

Changelog

Checklists

All Submissions:

  • I've signed all my commits
  • I followed the contribution guidelines
  • I ran cargo fmt and cargo clippy before committing
  • I've added exactly one changelog:* label
  • I've linked the relevant upstream docs or specs above

New Features:

  • I've added tests for the new feature
  • I've added docs for the new feature

Bugfixes:

  • This pull request breaks the existing API
  • I've added tests to reproduce the issue which are now passing
  • I'm linking the issue being fixed by this PR

@j-kon j-kon 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.

Two follow-ups before merge: this changes the exported error variant shape, so changelog: breaking appears more appropriate than changelog: fixed; the branch also needs rebasing onto current master before its CI result is current.

Comment thread bdk-ffi/src/error.rs
BdkSignerError::UserCanceled => SignerError::UserCanceled,
BdkSignerError::InputIndexOutOfRange(_) => SignerError::InputIndexOutOfRange,
BdkSignerError::InputIndexOutOfRange(e) => SignerError::InputIndexOutOfRange {
error_message: e.to_string(),

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.

Could we expose e.index and e.len as numeric fields instead of collapsing them into e.to_string()? #1096 specifically asks to preserve the offending index, but error_message makes foreign callers parse upstream display text. Since this already changes the exported variant shape and this repository supports numeric error fields, { index: u64, length: u64 } would provide a stable FFI contract while retaining the same Display message.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Thanks for the review. Did you try out the error display in any of the bindings? As I think this shows the index and the length clearly at least from the test in this PR.

but error_message makes foreign callers parse upstream display text.

Can you clarify ?

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.

Yes, the current display message does show both the index and the length clearly.

My point was more about the API exposed to the bindings rather than the human-readable error message itself.

With the current approach:

InputIndexOutOfRange { error_message: String }

a Swift/Kotlin/etc. caller gets the values only as part of a string like:

"Index out of bounds: index 3 is greater than or equal to length 1"

So if the binding user actually needs the offending index programmatically, they would have to parse that display string.

Upstream already exposes these as structured fields on IndexOutOfBoundsError:

  • index
  • len

So I was thinking we could preserve them directly in the FFI error, something along the lines of:

InputIndexOutOfRange {
index: u64,
length: u64,
}

while keeping the same Display message with:

#[error("Index out of bounds: index {index} is greater than or equal to length {length}")]

That way the error still reads exactly as it does now for humans, but binding callers also get stable numeric values without depending on the wording of the upstream Display implementation.

I haven't run the generated bindings for this PR specifically, so I'm not saying the current display is broken. The current approach works fine if the goal is only to improve the error message. I was mainly thinking about #1096's request to preserve the offending index as usable error data for binding consumers.

@ItoroD ItoroD Sep 7, 2026

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

#1096 request to preserve offending index was because index nor length was not displayed at all. It complete dropped the error message coming from upstream and gives its own fixed error display "input index out of range". My changes now carry the actual error from upstream which contains the len and index.

Preserving offending index is not necessarily saying we should expose the InputIndexOutOfRange as a strong type, its saying the len and index should not be discard from bindings layer. Note that we have many other errors where we use the { error_message: String } instead of using the type itself. We typically are not trying to expose all errors from upstream as types. That has not been the pattern at least (I stand to be corrected). But I certainly see your point about the users having to parse the string if they need to fetch the index and all.

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.

That makes sense, and I agree that error_message: String is already an established pattern for several wrapped upstream errors in bdk-ffi.

My concern was mainly that #1096 specifically talks about preserving the offending index, and since this variant is already changing shape, exposing index/len would make that information programmatically usable instead of only visible in the display string.

But I don't think this needs to turn into a broader change in how bdk-ffi models upstream errors. If the preferred convention here is to preserve the upstream display through error_message, I'm fine with that approach.

The other two things from my review still apply though: this is an API break, so changelog: breaking seems appropriate, and the branch still needs to be rebased onto current master.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Yes, changelog updated. It will be rebased when we are nearly ready to merge them. i.e (after non-breaking changes are merged)

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.

“Yes, changelog updated. It will be rebased when we are nearly ready to merge them. i.e (after non-breaking changes are merged)”

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

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

Preserve the index in InputIndexOutOfRange errors

2 participants