Frontend error refactoring
Eventually fixes #267 (closed). This is a work in progress preview of the work I'm doing on the refactoring of the error format, to make it consistent with the frontend. I have explored various designs, but I have settled on the following:
- We have a top-level type called
FrontendError
, which is opaque and captures two things: theBackendErrorCode
, which is a "tag" uniquely identifying the particular error code that the server is emitting, and a specific payload which depends on the givenBackendErrorCode
. The relationship between aBackendErrorCode
and its associated payload is bijective, i.e. there is a 1:1 mapping between the two. This makes for a slightly more verbose internals but the advantage is that we can be very precise in shaping the associated frontend error given a backend error.
Apart from this, I have now renamed the old GargError
to be called BackendInternalError
, and the idea is that throughout the backend server we throw internal backend errors and then at "the boundaries" (i.e. close to the application surface) we perform the conversion between a BackendInternalError
and a FrontendError
. We don't have to do this ourselves: this is done automatically as part of the backendErrorToFrontendError
function which is currently WIP (we have a bunch of undefined
there).
Last but not least, in the Main
code that turns a Servant server into a WAI
Application
we will eventually call frontendErrorToServerError
, which is responsible to generate a suitable ServerError
(<- the servant type) which will render nicely and consistently on the frontend side.
The idea is that now the frontend will always have a valid BackendErrorCode
tag returned in the error, and parsers can be written to process incoming JSON solely based on this tag.
What's remaining for this MR to become ready:
-
✅ We need to fix all the;undefined
- We need to replace all the
panic
anderror
we throw in the handlers with properBackendInternalError
; - Switch the main loop to call
frontendErrorToServerError
.
To be continued on Thursday and next week.