-
Notifications
You must be signed in to change notification settings - Fork 44
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Raise useful Horizon errors #95
base: main
Are you sure you want to change the base?
Conversation
Hi, thank you for the PR! Unfortunately, we did a mistake during the recent stellar-base/stellar-sdk merge which resulted in commit history for the base gem completely missing, and in order to fix this mistake we've had to force-push the master (and I did it just now). Could you please rebase your PR against the updated master? The new master should be identical to the old one as far as the repository content is concerned, it's just a commit history which changed, so your patches should apply perfectly. Really sorry about this mess. Also, I would suggest separating the bug fix and the error handling into different PRs. We definitely want to fix the base64 encoding bug for the upcoming release, but since we're in the rc1 stage already, I'm not sure if we should go ahead and include the error decoding part right now (also, as you pointed out, it needs some cleanup in regards to |
Of course! Done. The Base64 fix is now in #96. A simple test could take the form: When I send a payment to an uncreated account
Then I get a Stellar::HorizonError::TransactionFailed error |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @joallard, thank you very much for this contribution! Looks good, I've got just a couple of small remarks on it
sdk/lib/stellar/horizon_error.rb
Outdated
class HorizonError < StandardError | ||
attr_reader :original_response, :extras | ||
|
||
def self.make(hash) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since we then assigned the hash
parameter to the instance variable original_response
, I believe it's better to name it the same here. Also it would make it more accurate. The same goes for the initialize
method
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree!
sdk/lib/stellar/horizon_error.rb
Outdated
title = nil | ||
end | ||
|
||
[title, detail].join(": ") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For non-generic class title
will be nil
, and this expression will result in ": detail"
, which is not what we would like to get 🙂
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch! I'll add a compact
here
|
||
class TransactionFailed < self | ||
def make_message(detail:) | ||
detail.sub!( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't such substitution be useful on the generic level? In other words, can we show extras in the message for every error? If they exist, of course
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As far as I know, extras.result_codes
is only provided for TransactionFailed's. That said, I only checked 2 or 3 types.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A cursory search seems to confirm.
I think we can get rid of
|
Implements Stellar::HorizonError
Kudos, SonarCloud Quality Gate passed! 0 Bugs No Coverage information |
def make_message(detail:, title:) | ||
# Include title only on generic class | ||
# Condition passes only for child classes | ||
if self.class != HorizonError |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just noticed .instance_of?
existed
instance_of?(HorizonError)
a88d15e
to
e52ecc4
Compare
I caught this on the side while working on something else, my apologies for the missing tests; I didn't have time to figure out how to set up the accounts correctly just yet.
send_payment
request. The exception raised was as such:Which is not exactly helpful. Which is why I'm humbly proposing to wrap those into exceptions ourselves to raise some more useful information. It would now become:
It also makes available
.extras
on the exception. (On further thought,original_hash
should probably be namedoriginal_response
).[...]
After being done, I saw there were already
Stellar::AccountRequiresMemoError
andStellar::Horizon::Problem
, we could probably clean this up together if you'd like.Cheers!