-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: let Rel8 handle the JSON encoding/decoding of
App
s.
This makes our code a bit simpler. However, one major ramification of this change is that if an `App` cannot be successfully decoded when fetched from the database, this error condition will be dealt with by throwing an out-of-band exception, which is how we handle errors detected in the Rel8 or Hasql layers. Prior to this change, because our code in `querySessionId` was doing the decoding, we could handle decoding errors ourselves, and we would report these as a cryptic and somewhat unhelpful error to the student in the UI, in-band. In any case, this new way of handling errors as proper exceptions is more consistent with how we handle other catastrophic errors. After all, if a student's program can't be decoded when fetched from the database, this probably means that something has gone horribly wrong (a failed migration, data corruption, etc.), and should be handled appropriately.
- Loading branch information
Showing
4 changed files
with
46 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
{-# LANGUAGE DerivingVia #-} | ||
{-# LANGUAGE StandaloneDeriving #-} | ||
{-# OPTIONS_GHC -Wno-orphans #-} | ||
|
||
module Primer.Database.Rel8.OrphanInstances ( | ||
-- * Orphan instances | ||
-- $orphanInstances | ||
) where | ||
|
||
import Primer.App (App) | ||
import Rel8 ( | ||
DBType, | ||
JSONEncoded (..), | ||
) | ||
|
||
-- $orphanInstances | ||
-- | ||
-- In order to keep the Primer core library free of a "Rel8" | ||
-- dependency, we need to define a few orphan instances. | ||
|
||
deriving via (JSONEncoded App) instance (DBType App) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters