-
Notifications
You must be signed in to change notification settings - Fork 213
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
Make the NotEnoughMoney
API error machine-readable.
#4348
Make the NotEnoughMoney
API error machine-readable.
#4348
Conversation
NotEnoughMoney
a machine-readable error.NotEnoughMoney
a machine-readable API error.
91320a2
to
68a9d4d
Compare
fa71b0e
to
95f7f35
Compare
98f88e8
to
986b80c
Compare
aca2498
to
1ab2d97
Compare
36ef3c9
to
de9165b
Compare
1ab2d97
to
9e4ce91
Compare
de9165b
to
38ea1e2
Compare
9e4ce91
to
e903be4
Compare
NotEnoughMoney
a machine-readable API error.NotEnoughMoney
a machine-readable API error.
## Summary This PR forks the HTTP API error `not_enough_money` into two separate errors: - `not_enough_money` for when there **_really_** isn't enough money - `no_utxos_available` for when there **_might_** be enough money, but there are no UTxOs available These two cases can require subtly different workarounds from the user. ## Details This PR solves two problems. ### Problem 1 The `not_enough_money` error is **_inappropriate_** in the case where the reward balance alone would be sufficient to cover the amount required. For example, suppose a user has a wallet with: - no UTxOs; - an unspent reward balance of `1,000,000,000` ada. Suppose that the user attempts to make a payment transaction of `10` ada. In this case, the attempt will fail because: - every transaction is required to spend at least one UTxO; but - the wallet has no UTxOs available. But the user will receive a misleading `not_enough_money` error, even though they have more than enough money. This PR solves this problem by always using `no_utxos_available` when there are no UTxOs. ### Problem 2 In the case where UTxOs **_are_** available, but their value is insufficient, we currently attempt to embed information about the shortfall within the error message string: > ``` > I can't process this payment as there are not enough funds in the wallet. I am missing: > - lovelace: 123,456 lovelace > - assets: ... <information embedded within string> > ``` This information is valuable for UI clients that wish to inform users how much extra value they would need, but the information is tricky for UI clients to parse, as it's embedded within a **_string_**. We wish to turn the shortfall case into a **_machine-readable_** error with a specified JSON encoding (see #4348). However, this error would not be appropriate for the case where there are no UTxOs available at all, as there would not necessarily even be a "shortfall". This PR avoids this problem by giving the former case (no UTxOs available) its own dedicated error that will not be affected by #4348.
…This PR forks the HTTP API error `not_enough_money` into two separate errors: - `not_enough_money` for when there **_really_** isn't enough money - `no_utxos_available` for when there **_might_** be enough money, but there are no UTxOs available These two cases can require subtly different workarounds from the user. ## Details This PR solves two problems. ### Problem 1 The `not_enough_money` error is **_inappropriate_** in the case where the reward balance alone would be sufficient to cover the amount required. For example, suppose a user has a wallet with: - no UTxOs; - an unspent reward balance of `1,000,000,000` ada. Suppose that the user attempts to make a payment transaction of `10` ada. In this case, the attempt will fail because: - every transaction is required to spend at least one UTxO; but - the wallet has no UTxOs available. But the user will receive a misleading `not_enough_money` error, even though they have more than enough money. This PR solves this problem by always using `no_utxos_available` when there are no UTxOs. ### Problem 2 In the case where UTxOs **_are_** available, but their value is insufficient, we currently attempt to embed information about the shortfall within the error message string: > ``` > I can't process this payment as there are not enough funds in the wallet. I am missing: > - lovelace: 123,456 lovelace > - assets: ... <information embedded within string> > ``` This information is valuable for UI clients that wish to inform users how much extra value they would need, but the information is tricky for UI clients to parse, as it's embedded within a **_string_**. We wish to turn the shortfall case into a **_machine-readable_** error with a specified JSON encoding (see #4348). However, this error would not be appropriate for the case where there are no UTxOs available at all, as there would not necessarily even be a "shortfall". This PR avoids this problem by giving the former case (no UTxOs available) its own dedicated error that will not be affected by #4348. Source commit: 15f75af
5b3937b
to
be2e18c
Compare
NotEnoughMoney
a machine-readable API error.NotEnoughMoney
API error machine-readable.
We can verify that the `ApiErrorNotEnoughMoney` constructor has an info field.
be2e18c
to
885a999
Compare
specifications/api/swagger.yaml
Outdated
description: May occur when there's not enough money in the wallet to cover a requested payment. | ||
description: | | ||
Indicates that there's not enough money in the wallet to cover a | ||
requested payment. |
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.
Add a sentence that describes the shortfall
field in more detail.
Emphasise that the shortfall just describes the assets that are missing, and that if supplied, would unblock whatever operation it was that the user was attempting.
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.
Fixed in 0432db5.
In response to review feedback: #4348 (comment)
@@ -378,11 +377,6 @@ errMsg403NotAnIcarusWallet = | |||
"I cannot derive new address for this wallet type.\ | |||
\ Make sure to use a sequential wallet style, like Icarus." | |||
|
|||
errMsg403NotEnoughMoney :: String |
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.
🥇
Instead of inspecting the `message` string.
, expectErrorMessage errMsg403NotEnoughMoney | ||
] | ||
verify rTx [expectResponseCode HTTP.status403] | ||
decodeErrorInfo rTx `shouldSatisfy` \case |
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.
👍
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.
very nice PR
…# Issue ADP-3247 ## Description This PR revises the `NotEnoughMoney` API error so that it is machine-readable, with a well-defined schema. ## Example ```json { "code": "not_enough_money" , "message": "I can't process this payment as there are not enough funds available in the wallet." , "info": { "shortfall": { "ada": { "quantity": 1 , "unit": "lovelace" } , "assets": [ { "policy_id": "FRUIT" , "asset_name": "APPLE" , "quantity": 2 } , { "policy_id": "FRUIT" , "asset_name": "BANANA" , "quantity": 4 } ] } } } ``` Source commit: 4335f75
Issue
ADP-3247
Description
This PR revises the
NotEnoughMoney
API error so that it is machine-readable, with a well-defined schema.Example