Skip to content
This repository has been archived by the owner on Jun 11, 2022. It is now read-only.

[IOHKCRB-12] Improve error handling for wallet creation #542

Conversation

ecioppettini
Copy link
Contributor


name: [IOHKCRB-12] Add test of transaction creation

Description

Error handling

  • Make cardano_wallet_new return the created wallet as an out parameter and use the return value for the error code. This way it no longer returns a null pointer if the size of the entropy array is not valid.
  • Add the tests to validate that the error code is consistent

@ecioppettini ecioppettini force-pushed the IOHKCRB-12-improve-error-handling-for-wallet-creation branch from 5e254f0 to b461a72 Compare March 20, 2019 13:09
@NicolasDP NicolasDP self-requested a review March 20, 2019 14:39
@NicolasDP NicolasDP self-assigned this Mar 20, 2019
@ecioppettini ecioppettini marked this pull request as ready for review March 20, 2019 16:03
@ecioppettini ecioppettini force-pushed the IOHKCRB-12-improve-error-handling-for-wallet-creation branch from b461a72 to 6ae5c81 Compare March 21, 2019 19:04
@NicolasDP
Copy link
Contributor

Looking good, you might need to rebase your branch. The previous merge (#523 ) seems to have conflict with this one.

@vincenthz vincenthz self-requested a review March 22, 2019 10:17
Ok(e) => e,
};

let wallet = bip44::Wallet::from_entropy(&entropy, &password, hdwallet::DerivationScheme::V2);

let wallet_box = Box::new(wallet);
Box::into_raw(wallet_box)
unsafe { ptr::write(wallet_out, Box::into_raw(wallet_box)) };
Copy link
Member

Choose a reason for hiding this comment

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

might be a good idea to check the wallet_out pointer being non NULL and returning a friendly CardanoResult error if that's the case ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I see... The behavior is undefined in that case, wouldn't a panic with a message be better though? I think a null pointer here is most probably a bug in the caller?
Should I always check for null pointers?

Copy link
Member

@vincenthz vincenthz left a comment

Choose a reason for hiding this comment

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

looking good. this is exactly the kind of error handling I was talking about.

@vincenthz
Copy link
Member

Just need rebasing and then we can merge

@ecioppettini ecioppettini force-pushed the IOHKCRB-12-improve-error-handling-for-wallet-creation branch from 6ae5c81 to 753aff9 Compare March 22, 2019 13:01
@NicolasDP NicolasDP merged commit 802f4a6 into input-output-hk:master Mar 23, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants