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

Error message for mnemonics (mnemonic_sentence and mnemonic_second_factor) #192

Closed
piotr-iohk opened this issue Apr 29, 2019 · 1 comment
Assignees

Comments

@piotr-iohk
Copy link
Contributor

piotr-iohk commented Apr 29, 2019

Release Operating System Cause
next Linux Code

Context

Error message for mnemonic_sentence and mnemonic_second_factor need to be improved:

E.g. when doing POST v2\wallets and providing invalid mnemonic sentence or valid mnemonic sentence but with invalid length to one of the parameters the following error is returned:

Error in $['mnemonic_sentence']: ErrMnemonicWords (ErrWrongNumberOfWords 12 24)

  • the error is not really human friendly and can be misleading
  • it is faultly thrown for the case when the number of words is valid but mnemonics are invalid
  • it is faulty thrown for the non-english mnemonics (ErrMnemonicWords (ErrWrongNumberOfWords instead of ErrDictionary (ErrInvalidDictionaryWord)

Steps to Reproduce

Please note that examples are for mnemonic_sentence but the same situation adheres to mnemonic_second_factor.

  1. start cardano wallet launcher:
export NETWORK=testnet
stack exec -- cardano-wallet-launcher

Case 1 - invalid mnemonics, valid length

  1. Run post wallet with invalid mnemonics list, yet make sure list has valid length (e.g. 15)
curl  -vX POST http://localhost:8090/v2/wallets \
  -H "Accept: application/json; charset=utf-8" \
  -H "Content-Type: application/json; charset=utf-8" \
  -d '{
"name": "Piotr Wallet",
"mnemonic_sentence": ["word","word","word","word","word","word","word","word","word","word","word","word","word","word","word"],
"passphrase": "Secure Passphrase",
"address_pool_gap": 20
}' --http1.1

Case 2 - valid mnemonics, invalid length

  1. Run post wallet with valid mnemonics list, yet make sure list has invalid length (e.g. 9)
curl  -vX POST http://localhost:8090/v2/wallets \
  -H "Accept: application/json; charset=utf-8" \
  -H "Content-Type: application/json; charset=utf-8" \
  -d '{
"name": "Piotr Wallet",
"mnemonic_sentence": ["subway", "tourist", "abstract", "roast", "border", "curious",
        "exercise", "work", "narrow"],
"passphrase": "Secure Passphrase",
"address_pool_gap": 20
}' --http1.1

Case 3 - valid, yet non-english mnemonics

curl  -vX POST http://localhost:8090/v2/wallets \
  -H "Accept: application/json; charset=utf-8" \
  -H "Content-Type: application/json; charset=utf-8" \
  -d '{
"name": "Piotr Wallet",
"mnemonic_sentence": ["盗", "精", "序", "郎", "赋", "姿", "委", "善", "酵",
        "祥", "赛", "矩", "蜡", "注", "韦", "效", "义", "冻"],
"passphrase": "Secure Passphrase",
"address_pool_gap": 20
}' --http1.1

Expected behavior

Case 1 - invalid mnemonics, valid length
The error should be rather something like:
Error in $['mnemonic_sentence']: The list of provided mnemonic words is invalid.

Case 2 - valid mnemonics, invalid length
The error should be rather something like:
Error in $['mnemonic_sentence']: The list of provided mnemonic is too short (9). Supported lengths are 15,18,21,24.

Case 3 - valid, yet non-english mnemonics
Error in $['mnemonic_sentence']: Non-english mnemonic words are not supported

Actual behavior

Case 1 - invalid mnemonics, valid length

The error message returned for the case is:
Error in $['mnemonic_sentence']: ErrMnemonicWords (ErrWrongNumberOfWords 15 24)

Case 2 - valid mnemonics, invalid length
The error message returned for the case is:
Error in $['mnemonic_sentence']: ErrMnemonicWords (ErrWrongNumberOfWords 9 24)

Case 3 - valid, yet non-english mnemonics
Actually the same error is returned -> Error in $['mnemonic_sentence']: ErrMnemonicWords (ErrWrongNumberOfWords 9 24) instead of expected ErrDictionary (ErrInvalidDictionaryWord .... However even the ErrDictionary (ErrInvalidDictionaryWord ... should be polished to be informative and user-friendly as indicated in Expected behavior.


Resolution Plan

  • The FromMnemonic class used to parse a list of mnemonic words of variable length seems to only report the last error encountered in the list.
  • Introducing some failing test case to illustrate this hypothesis and then, if confirmed, fixing it it the way to go.

PR

Number Base
#197 master

QA

@piotr-iohk piotr-iohk changed the title Error message for mnemonics Error message for mnemonics (mnemonic_sentence and mnemonic_second_factor) Apr 29, 2019
@piotr-iohk piotr-iohk added the BUG label Apr 29, 2019
@KtorZ KtorZ mentioned this issue Apr 30, 2019
2 tasks
@KtorZ KtorZ self-assigned this Apr 30, 2019
@piotr-iohk
Copy link
Contributor Author

lgtm 👍
tested on #194

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

No branches or pull requests

2 participants