serokell / coffer

Multi-backend password store with multiple frontends
4 stars 2 forks source link

Improve error handling #24

Closed dcastro closed 2 years ago

dcastro commented 2 years ago
  1. The exception handler in Backend.Vault.Kv swallows a lot of info about thrown exceptions.
          \case FailureResponse _request response ->
                    case statusCode $ responseStatusCode response of
                      404 -> Nothing
                      e -> Just $ OtherError (T.pack $ show e)
                DecodeFailure text response -> Just MarshallingFailed
                UnsupportedContentType mediaType response -> Just MarshallingFailed
                InvalidContentTypeHeader response -> Just MarshallingFailed
                ConnectionError exception -> Just ConnectError
  1. In a few places we're also throwing MarshallingFailed without specifying why it failed (what we expected to receive, what we actually received).
        case response ^. I.ddata . at ("version" :: T.Text) of
          Just (A.Number i) -> maybe (throw MarshallingFailed) pure (S.toBoundedInteger i)
          _ -> throw MarshallingFailed
        maybeThrow = maybe (throw MarshallingFailed) pure
  1. We also throw OtherError "404" without specifying which request failed.
throw $ OtherError "404"
  1. We use eitherToMaybe that swallows error messages.

This makes exceptions extremely hard to troubleshoot.

We should make sure as much info as possible is preserved and displayed to the user.

Additionally, we should write a Buildable instance for CofferError and change the CLI to pretty-print error messages.

Acceptance Criteria