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

Provide meaningful exception messages #47

Open
eximius313 opened this issue Feb 25, 2018 · 4 comments
Open

Provide meaningful exception messages #47

eximius313 opened this issue Feb 25, 2018 · 4 comments

Comments

@eximius313
Copy link

eximius313 commented Feb 25, 2018

This code:

Iban build = new Iban.Builder()
        .countryCode(CountryCode.PL)
        .bankCode("22876")
        .accountNumber("63810519014")
        .build();
    System.out.println(build);

throws following exception:

Exception in thread "main" org.iban4j.IbanFormatException: [76nu] must contain only digits.
	at org.iban4j.IbanUtil.validateBbanEntryCharacterType(IbanUtil.java:409)
	at org.iban4j.IbanUtil.validateBbanEntries(IbanUtil.java:379)
	at org.iban4j.IbanUtil.validate(IbanUtil.java:80)
	at org.iban4j.Iban$Builder.build(Iban.java:365)
	at org.iban4j.Iban$Builder.build(Iban.java:337)

And what is even more weird, this code:

    Iban randomIban = Iban.random(CountryCode.PL);
    Iban build = new Iban.Builder()
        .countryCode(CountryCode.PL)
        .bankCode(randomIban.getBankCode())
        .accountNumber(randomIban.getAccountNumber())
        .build();

throws following exception:

Exception in thread "main" org.iban4j.IbanFormatException: [270nullnull2789991694524099] length is 27, expected BBAN length is: 24
	at org.iban4j.IbanUtil.validateBbanLength(IbanUtil.java:362)
	at org.iban4j.IbanUtil.validate(IbanUtil.java:79)
	at org.iban4j.Iban$Builder.build(Iban.java:365)
	at org.iban4j.Iban$Builder.build(Iban.java:337)

what's wrong?

@arturmkrtchyan
Copy link
Owner

arturmkrtchyan commented Feb 25, 2018

Polish IBAN's have the following structure:

.countryCode(CountryCode.PL)
.bankCode("109")
.branchCode("0101")
.accountNumber("0000071219812874")
.nationalCheckDigit("4")

@eximius313
Copy link
Author

eximius313 commented Feb 25, 2018

Could I ask then for more meaningful error messages in both cases and treat this issue as a Improvement Request?
Something like:
"branchCode" is required for requested CountryCode: XY
"nationalCheckDigit" is required for requested CountryCode: XY

@arturmkrtchyan
Copy link
Owner

Absolutely!
Lately I have not been actively adding feature requests, but going forward I'm planning to dedicate some time to it.

@eximius313
Copy link
Author

Thank you so much!
I spend a lot of time debugging why [76nu] must contain only digits despite I provided only digits :)

@eximius313 eximius313 changed the title "Must contain only digits" exception Provide meaningful exception messages Feb 25, 2018
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