fcli icon indicating copy to clipboard operation
fcli copied to clipboard

Code Quality: Error & exception handling

Open rsenden opened this issue 4 years ago • 3 comments

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

rsenden avatar Oct 27 '21 18:10 rsenden

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.

rsenden avatar Nov 16 '21 17:11 rsenden

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.

rsenden avatar Sep 14 '22 21:09 rsenden

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.

rsenden avatar Jul 26 '23 13:07 rsenden

Closing as fcli v3.0.0 introduces several improvements and a more structured approach for example handling with its own AbstractFcliException class hierarchy

rsenden avatar Mar 18 '25 12:03 rsenden