#201 Improper error handling
Closed: fixed by edewata. Opened by edewata.

If an error happens in a method, in many cases the method would catch and swallow the exception, then return null. It would be difficult for the caller to figure out what's causing the problem and then handle it properly. Ideally a method should throw an exception if there is an error, and return null only if null is a valid return value for that method (e.g. object not found). For example:

public Cert getUserCert(String id) {
    try {
        ... find user & parse cert ...
        return cert;
    } catch (Exception e);
        return null;
    }
}
public void caller() {
    Cert cert = getUserCert("test");
    if (cert == null) {
        // It could be caused by:
        // - user not found
        // - other LDAP error
        // - invalid cert
        // - user has no cert
    }
}

It should be replaced with:

public Cert getUserCert(String id) throws Exception {
    ... find user & parse cert...
    return user;
}
public void caller() {
    try {
        Cert cert = getUserCert("test");
        if (cert == null) {
            // user has no cert
        }
    } catch (LDAPException e) {
        if (e.getResultCode() == 32) {
            // user not found
        } else {
            // other LDAP error
        }
    } catch (ParsingException e) {
        // invalid cert
    }
}

Metadata Update from @edewata:
- Issue assigned to vakwetu
- Issue set to the milestone: UNTRIAGED

This is a continuous improvement, no need to keep track.

Metadata Update from @edewata:
- Custom field feature adjusted to None
- Custom field proposedmilestone adjusted to None (was: Future)
- Custom field reviewer adjusted to None
- Custom field version adjusted to None
- Issue close_status updated to: fixed
- Issue status updated to: Closed (was: Open)

Dogtag PKI is moving from Pagure issues to GitHub issues. This means that existing or new
issues will be reported and tracked through Dogtag PKI's GitHub Issue tracker.

This issue has been cloned to GitHub and is available here:
https://github.com/dogtagpki/pki/issues/772

If you want to receive further updates on the issue, please navigate to the
GitHub issue and click on Subscribe button.

Thank you for understanding, and we apologize for any inconvenience.

Metadata