Error Handling

SmartFaker raises ValueError for every invalid input.

Address errors

from smartfaker import Faker

faker = Faker()

try:
    faker.address("zz")
except ValueError as exc:
    print("address failed:", exc)

Cases that raise ValueError:

  • empty country code

  • unknown country code (no bundled data)

  • country bucket present but empty

IBAN errors

try:
    faker.iban("XX")
except ValueError as exc:
    print("iban failed:", exc)

Cases that raise ValueError:

  • empty country code

  • country code not in smartfaker.iban.COUNTRY_GENERATORS

  • generated IBAN failed length or MOD-97 self-check (defensive — should not happen with the bundled generators, but is checked anyway)

Batch behaviour

batch_addresses() and abatch_addresses() are deliberately tolerant — unknown country codes are skipped and omitted from the result mapping rather than raising. Validate the returned keys instead:

res = faker.batch_addresses(["us", "xx", "gb"])
assert set(res) == {"US", "GB"}