# Buggy code
def _find_domains_or_certname(config, installer):
    """Retrieve domains and certname from config or user input."""
    domains = None
    if config.domains:
        domains = config.domains
    elif not config.certname:
        domains = display_ops.choose_names(installer)

    if not domains and not config.certname:
        raise errors.Error(
            "Please specify --domains, or --installer that "
            "will help in domain names autodiscovery, or "
            "--cert-name for an existing certificate name."
        )

    return domains, config.certname


# Traceback (TypeError)
certbot certificates
Saving debug log to /var/log/letsencrypt/letsencrypt.log

-------------------------------------------------------------------------------
Found the following certs:
Certificate Name: isnot.org
Domains: isnot.org goxogle.com is.isnot.org www.isnot.org
Expiry Date: 2017-03-20 17:57:00+00:00 (VALID: 89 days)
Certificate Path: /etc/letsencrypt/live/isnot.org/fullchain.pem
Private Key Path: /etc/letsencrypt/live/isnot.org/privkey.pem
...

certbot --cert-name isnot.org --debug
Saving debug log to /var/log/letsencrypt/letsencrypt.log
Starting new HTTPS connection (1): acme-v01.api.letsencrypt.org
Cert not yet due for renewal

You have an existing certificate that has exactly the same domains or certificate name you requested and isn't close to expiry.
(ref: /etc/letsencrypt/renewal/isnot.org.conf)

What would you like to do?
-------------------------------------------------------------------------------
1: Attempt to reinstall this existing certificate
2: Renew &amp; replace the cert (limit ~5 per 7 days)
-------------------------------------------------------------------------------
Select the appropriate number [1-2] then [enter] (press 'c' to cancel): 1
Keeping the existing certificate
Traceback (most recent call last):
File "venv/bin/certbot", line 11, in <module>
load_entry_point('certbot', 'console_scripts', 'certbot')()
File "/home/ubuntu/letsencrypt/certbot/main.py", line 831, in main
return config.func(config, plugins)
File "/home/ubuntu/letsencrypt/certbot/main.py", line 570, in run
lineage.chain, lineage.fullchain)
File "/home/ubuntu/letsencrypt/certbot/client.py", line 380, in deploy_certificate
for dom in domains:
TypeError: 'NoneType' object is not iterable

# Fixed code
def _find_domains_or_certname(config, installer):
    """Retrieve domains and certname from config or user input."""
    domains = None
    certname = config.certname
    # first, try to get domains from the config
    if config.domains:
        domains = config.domains
    # if we can't do that but we have a certname, get the domains
    # with that certname
    elif certname:
        domains = cert_manager.domains_for_certname(config, certname)

    # that certname might not have existed, or there was a problem.
    # try to get domains from the user.
    if not domains:
        domains = display_ops.choose_names(installer)

    if not domains and not certname:
        raise errors.Error(
            "Please specify --domains, or --installer that "
            "will help in domain names autodiscovery, or "
            "--cert-name for an existing certificate name."
        )

    return domains, certname