Export Display trait on errors#1021
Open
thunderbiscuit wants to merge 1 commit into
Open
Conversation
Collaborator
|
@thunderbiscuit This is ineresting for the swift side I can see the difference this is making. For kotlin, are you saying we will have to implement a custom display method (Just to clarify). Edit - I guess not cause that will then affect all bindings. |
Collaborator
|
Concept ACK |
j-kon
reviewed
Jul 7, 2026
| } | ||
|
|
||
| #[derive(Debug, thiserror::Error, uniffi::Error)] | ||
| #[uniffi::export(Debug, Display)] |
Contributor
There was a problem hiding this comment.
Since the PR title/changelog describe exporting Display on errors broadly, should this export be applied to the other uniffi::Error enums in this file too, or should the PR scope be narrowed to CreateWithPersistError only? Right now this is the only error type getting Debug/Display exported to the bindings.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This brings the Display trait we create using the
thiserror::Errormacro to the bindings. We've been implementing the Display trait for all this time, but not passing it on to the bindings!Note that the draft version of this PR implements this just for the
CreateWithPersistErrorenum.See related issues #509 and #964.
Todo
http error with status code 404 and message 'Block not found'instead ofhttp error with status code 404 and message Block not found. Just an idea.In Practice
Here is what this means in practice:
Kotlin
The default toString() method on Exceptions (
className + ": " + message) is overriden by the Display trait. You loose the className when the exception is printed out, but you gain the human-readable message we maintain in the crate. If you want the Exception type, you can still print it. You keep the strongly typed fields (in the example below yourstatusfield is aUShort), and themessagefield is just a stringified concatenation of all the fields. This means you have to know that on BDK exceptions, the human-readable message is not in fact in themessagefield like you expect on typical Kotlin errors, but instead in thetoString()method.Swift
In Swift, two new fields are added to the errors:
descriptionanddebugDescription. Thedescriptionfield now holds the human-readable messages we craft on the structs usingthiserror. The `debugDescription is just the Debug trait on Rust. Note that this is not available in Kotlin, as there is not equivalent "debug" print method or field.Changelog
Checklists
All Submissions:
cargo fmtandcargo clippybefore committingchangelog:*labelNew Features:
Bugfixes: