Skip to content
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

[ADP-3306] Make NoSuchWallet error machine-readable. #4597

Merged
merged 26 commits into from
May 23, 2024

Conversation

paweljakubas
Copy link
Contributor

@paweljakubas paweljakubas commented May 17, 2024

  • Extend NoSuchWallet to include WalletId.
  • Adjust unit tests and swagger accordingly.
  • use NoSuchWallet rather than err403NoSuchErrorMsg throughout integration tests

Issue

ADP-3306

Copy link
Member

@jonathanknowles jonathanknowles left a comment

Choose a reason for hiding this comment

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

Hi @paweljakubas

Thanks for making this PR! I've left a few suggestions.

I believe the unit test failure will be fixed by: #4598.

One last request: would it be possible to fill out the PR description?

Many thanks again!

lib/api/src/Cardano/Wallet/Api/Types/Error.hs Outdated Show resolved Hide resolved
@@ -312,3 +315,10 @@ data ApiErrorNoSuchPool = ApiErrorNoSuchPool
deriving (Data, Eq, Generic, Show, Typeable)
deriving (FromJSON, ToJSON) via DefaultRecord ApiErrorNoSuchPool
deriving anyclass NFData

data ApiErrorNoSuchWallet = ApiErrorNoSuchWallet
{ walletId :: !Text
Copy link
Member

Choose a reason for hiding this comment

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

Suggestion: does it make sense to use ApiT WalletId here?

Suggested change
{ walletId :: !Text
{ walletId :: !(ApiT WalletId)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

trying to use pattern synonyms here -> 984bb6e

]
decodeErrorInfo r `Lifted.shouldBe`
(NoSuchWallet $ ApiErrorNoSuchWallet $ w ^. walletId)
Copy link
Member

Choose a reason for hiding this comment

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

For cases like this, I would suggest:

Suggested change
(NoSuchWallet $ ApiErrorNoSuchWallet $ w ^. walletId)
NoSuchWallet (ApiErrorNoSuchWallet $ w ^. walletId)

Copy link
Member

Choose a reason for hiding this comment

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

(I think hlint highlights a series of similar cases.)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

indeed, done

Copy link
Member

Choose a reason for hiding this comment

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

@@ -4361,6 +4361,18 @@ x-errNoUtxosAvailable: &errNoUtxosAvailable
type: string
enum: ['no_utxos_available']

x-errNoSuchWalletInitialized: &errNoSuchWalletInitialized
Copy link
Member

@jonathanknowles jonathanknowles May 20, 2024

Choose a reason for hiding this comment

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

Related to #4597 (comment) (above):

Suggested change
x-errNoSuchWalletInitialized: &errNoSuchWalletInitialized
x-errWalletNotInitialized: &errWalletNotInitialized

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@@ -4361,6 +4361,18 @@ x-errNoUtxosAvailable: &errNoUtxosAvailable
type: string
enum: ['no_utxos_available']

x-errNoSuchWalletInitialized: &errNoSuchWalletInitialized
<<: *responsesErr
title: no_such_wallet_initialized
Copy link
Member

@jonathanknowles jonathanknowles May 20, 2024

Choose a reason for hiding this comment

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

Related to #4597 (comment) (above):

Suggested change
title: no_such_wallet_initialized
title: wallet_not_initialized

specifications/api/swagger.yaml Outdated Show resolved Hide resolved
@@ -5627,6 +5645,13 @@ x-responsesErr404WalletNotFound: &responsesErr404WalletNotFound
application/json:
schema: *errNoSuchWallet

x-responsesErr404DbNotInitialized: &responsesErr404DbNotInitialized
404:
description: DB uninitialized
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
description: DB uninitialized
description: Wallet not yet initialized.

@jonathanknowles jonathanknowles changed the title Refactor no such wallet error [ADP-3306] Refactor NoSuchWallet error. May 20, 2024
paweljakubas added a commit that referenced this pull request May 20, 2024
…SchemaApiErrorInfo`. (#4598)

This PR makes a small fix for #4597.

## Issue

ADP-3306
@jonathanknowles jonathanknowles changed the title [ADP-3306] Refactor NoSuchWallet error. [ADP-3306] Make NoSuchWallet error machine-readable. May 22, 2024
@paweljakubas paweljakubas force-pushed the paweljakubas/adp-3306/refactor-no-such-wallet branch from 9dc071b to 984bb6e Compare May 22, 2024 15:12
This is necessary, as type `ApiErrorNoSuchWallet` uses a real `WalletId`
instead of just `Text`.
@jonathanknowles jonathanknowles force-pushed the paweljakubas/adp-3306/refactor-no-such-wallet branch from 984bb6e to c9a339a Compare May 23, 2024 06:45
Copy link
Member

@jonathanknowles jonathanknowles left a comment

Choose a reason for hiding this comment

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

LGTM!

@paweljakubas, many thanks for making this PR!

@jonathanknowles jonathanknowles enabled auto-merge May 23, 2024 08:37
This particular test happens to use `rawRequest` instead of `request`.
Whereas the `request` function attempts to decode the response into a
JSON `Value`, the `rawRequest` function does not perform any decoding.

This causes the subsequent `decodeErrorInfo` to fail with:

```
  uncaught exception: ErrorCall
   decodeErrorInfo: Expected a 'ClientError', but encountered something else: Left (RawClientError "{\"code\":\"no_such_wallet\",\"info\":{\"wallet_id\":\"acab1951ad1ef5808eb9756b02d1ff85caf0e702\"},\"message\":\"I couldn't find a wallet with the given id: acab1951ad1ef5808eb9756b02d1ff85caf0e702\"}")
   CallStack (from HasCallStack):
     error, called at framework/Test/Integration/Framework/DSL.hs:742:13 in cardano-wallet-integration-2024.5.5-KhWmuWPIqBp7pTemTBE3I2-framework:Test.Integration.Framework.DSL
     decodeErrorInfo, called at scenarios/Test/Integration/Scenario/API/Shelley/Wallets.hs:1495:9 in cardano-wallet-integration-2024.5.5-AcHGWrd1jBGKoKhY01VJRG-scenarios:Test.Integration.Scenario.API.Shelley.Wallets
```
@jonathanknowles jonathanknowles added this pull request to the merge queue May 23, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks May 23, 2024
@jonathanknowles jonathanknowles added this pull request to the merge queue May 23, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks May 23, 2024
@paweljakubas paweljakubas added this pull request to the merge queue May 23, 2024
Merged via the queue into master with commit 8faf0a2 May 23, 2024
3 checks passed
@paweljakubas paweljakubas deleted the paweljakubas/adp-3306/refactor-no-such-wallet branch May 23, 2024 12:26
WilliamKingNoel-Bot pushed a commit that referenced this pull request May 23, 2024
…- [x] Extend `NoSuchWallet` to include `WalletId`. - [x] Adjust unit tests and swagger accordingly. - [x] use `NoSuchWallet` rather than `err403NoSuchErrorMsg` throughout integration tests ### Issue ADP-3306 Source commit: 8faf0a2
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.

2 participants