serokell / coffer

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

Create backend-specific error types #72

Closed dcastro closed 2 years ago

dcastro commented 2 years ago

Clarification and motivation

As of #60, we're using the following definition for CofferError:

data CofferError
  = ServantError ClientError
  | BackendNotFound BackendName
  | OtherError Builder

There are 2 issues here:

  1. In the Backend.Vault.Kv module, we're constructing OtherError with user-facing error messages as strings. We should follow the same pattern we're using everywhere else and construct a proper ADT + a Buildable instance.
  2. CofferError is meant to be backend-agnostic, but it assumes that all backends will (possibly) throw a ServantError. However, this assumption is not true - the pass backend, for example, does not use servant.

The proposed solution is to refactor the CofferError such that it can wrap any backend-specific error:

data CofferError where
  ...
  BackendError :: Buildable err => err -> CofferError

And then create backend-specific error types, with proper constructors,and move the ServantError constructor:

data VaultError
  = ServantError ClientError
  | FieldMetadataNotFound EntryPath FieldName
  | ...

Acceptance criteria

  1. We're using ADTs + Buildable to model errors, and not just building ad-hoc strings with error messages.
  2. CofferError is backend-agnostic, and the haddocks make this explicit.
  3. We have backend-specific error types (at the moment, it's just VaulError)