Code Quality: Error & exception handling
Tasks:
-
HTTP response codes:
- Properly handle non-20x HTTP responses
- Non-20x responses should result in non-zero exit code
- Error data (body, status code, ...) should be returned in the format specified by --format option if possible
-
Exception handling:
- Review use of
@SneakyThrows, do we want to use this? - Is there nay need to have a picocli exception handler, for example to provide more user-friendly error messages?
- Make sure that exceptions result in non-zero exit code
- Make sure that exceptions are also written to any logs
- Review use of
Non-20x responses now generate an exception. We have chosen to just propagate the exception to the user, rather than trying to wrap it in the configured output format. This ensures that processing is interrupted and appropriate error code is returned.
We still need to review the use of SneakyThrows, and verify that (fatal) exceptions are written to the logs.
When encountering an error, we mostly throw standard Java exceptions like IllegalStateException/IllegalArgumentException, with hardcoded messages. Better would be to use custom exceptions that include a message resource key, to allow for internationalization of the error messages.
We only support English language for now, so the ability to support internationalized error messages is low priority for now. Eventually we should come up with some generic best practices for error & exception management, but again low priority for now.
Closing as fcli v3.0.0 introduces several improvements and a more structured approach for example handling with its own AbstractFcliException class hierarchy