Commit c53f2d10 authored by Grégoire Locqueville's avatar Grégoire Locqueville

Add an `InvalidNodeType` constructor to the `NodeError` type

This aims to deal with cases where the `typename` field of the `nodes` table
does not correspond to a valid node type.
The new constructor has an Integer field to indicate what the stored
invalid type name ID was.
The related machinery was updated accordingly.
parent 0b5ce744
Pipeline #6622 passed with stages
in 56 minutes and 54 seconds
...@@ -127,6 +127,8 @@ jobErrorToFrontendError = \case ...@@ -127,6 +127,8 @@ jobErrorToFrontendError = \case
nodeErrorToFrontendError :: NodeError -> FrontendError nodeErrorToFrontendError :: NodeError -> FrontendError
nodeErrorToFrontendError ne = case ne of nodeErrorToFrontendError ne = case ne of
InvalidNodeType typeId
-> mkFrontendErrShow $ FE_invalid_node_type typeId
NoListFound lid NoListFound lid
-> mkFrontendErrShow $ FE_node_list_not_found lid -> mkFrontendErrShow $ FE_node_list_not_found lid
NoRootFound NoRootFound
......
...@@ -177,6 +177,10 @@ $(deriveIsFrontendErrorData ''BackendErrorCode) ...@@ -177,6 +177,10 @@ $(deriveIsFrontendErrorData ''BackendErrorCode)
data NoFrontendErrorData = NoFrontendErrorData data NoFrontendErrorData = NoFrontendErrorData
newtype instance ToFrontendErrorData 'EC_404__invalid_node_type =
FE_invalid_node_type { int_nodetype_id :: Int }
deriving (Show, Eq, Generic)
newtype instance ToFrontendErrorData 'EC_404__node_list_not_found = newtype instance ToFrontendErrorData 'EC_404__node_list_not_found =
FE_node_list_not_found { lnf_list_id :: ListId } FE_node_list_not_found { lnf_list_id :: ListId }
deriving (Show, Eq, Generic) deriving (Show, Eq, Generic)
...@@ -337,6 +341,14 @@ data instance ToFrontendErrorData 'EC_405__not_allowed = ...@@ -337,6 +341,14 @@ data instance ToFrontendErrorData 'EC_405__not_allowed =
-- payload, we can render it to JSON and parse it back. -- payload, we can render it to JSON and parse it back.
---------------------------------------------------------------------------- ----------------------------------------------------------------------------
instance ToJSON (ToFrontendErrorData 'EC_404__invalid_node_type) where
toJSON (FE_invalid_node_type nodetypeId) =
object [ "nodetype_id" .= toJSON nodetypeId ]
instance FromJSON (ToFrontendErrorData 'EC_404__invalid_node_type) where
parseJSON = withObject "FE_invalid_node_type" $ \o -> do
nodetypeId <- o .: "nodetype_id"
pure $ FE_invalid_node_type nodetypeId
instance ToJSON (ToFrontendErrorData 'EC_404__node_list_not_found) where instance ToJSON (ToFrontendErrorData 'EC_404__node_list_not_found) where
toJSON (FE_node_list_not_found lid) = toJSON (FE_node_list_not_found lid) =
object [ "list_id" .= toJSON lid ] object [ "list_id" .= toJSON lid ]
...@@ -587,6 +599,8 @@ genFrontendErr be = do ...@@ -587,6 +599,8 @@ genFrontendErr be = do
case be of case be of
-- node errors -- node errors
EC_404__invalid_node_type
-> arbitrary >>= \nodetypeId -> pure $ mkFrontendErr' txt $ FE_invalid_node_type nodetypeId
EC_404__node_list_not_found EC_404__node_list_not_found
-> arbitrary >>= \lid -> pure $ mkFrontendErr' txt $ FE_node_list_not_found lid -> arbitrary >>= \lid -> pure $ mkFrontendErr' txt $ FE_node_list_not_found lid
EC_404__node_root_not_found EC_404__node_root_not_found
...@@ -711,6 +725,9 @@ instance FromJSON FrontendError where ...@@ -711,6 +725,9 @@ instance FromJSON FrontendError where
(fe_diagnostic :: T.Text) <- o .: "diagnostic" (fe_diagnostic :: T.Text) <- o .: "diagnostic"
(fe_type :: BackendErrorCode) <- o .: "type" (fe_type :: BackendErrorCode) <- o .: "type"
case fe_type of case fe_type of
EC_404__invalid_node_type -> do
(fe_data :: ToFrontendErrorData 'EC_404__invalid_node_type) <- o .: "data"
pure FrontendError{..}
EC_404__node_list_not_found -> do EC_404__node_list_not_found -> do
(fe_data :: ToFrontendErrorData 'EC_404__node_list_not_found) <- o .: "data" (fe_data :: ToFrontendErrorData 'EC_404__node_list_not_found) <- o .: "data"
pure FrontendError{..} pure FrontendError{..}
......
...@@ -16,7 +16,8 @@ import Prelude ...@@ -16,7 +16,8 @@ import Prelude
data BackendErrorCode data BackendErrorCode
= =
-- node errors -- node errors
EC_404__node_list_not_found EC_404__invalid_node_type
| EC_404__node_list_not_found
| EC_404__node_root_not_found | EC_404__node_root_not_found
| EC_404__node_lookup_failed_not_found | EC_404__node_lookup_failed_not_found
| EC_404__node_lookup_failed_parent_not_found | EC_404__node_lookup_failed_parent_not_found
......
...@@ -70,7 +70,8 @@ renderNodeLookupFailed = \case ...@@ -70,7 +70,8 @@ renderNodeLookupFailed = \case
UserHasTooManyRoots uid roots -> "user with id " <> T.pack (show uid) <> " has too many roots: [" <> T.intercalate "," (map (T.pack . show) roots) UserHasTooManyRoots uid roots -> "user with id " <> T.pack (show uid) <> " has too many roots: [" <> T.intercalate "," (map (T.pack . show) roots)
------------------------------------------------------------------------ ------------------------------------------------------------------------
data NodeError = NoListFound ListId data NodeError = InvalidNodeType Int
| NoListFound ListId
| NoRootFound | NoRootFound
| NoCorpusFound | NoCorpusFound
| NodeCreationFailed NodeCreationError | NodeCreationFailed NodeCreationError
...@@ -84,6 +85,7 @@ data NodeError = NoListFound ListId ...@@ -84,6 +85,7 @@ data NodeError = NoListFound ListId
instance Prelude.Show NodeError instance Prelude.Show NodeError
where where
show (InvalidNodeType id) = "Invalid node type ID: " <> show id
show (NoListFound {}) = "No list found" show (NoListFound {}) = "No list found"
show NoRootFound = "No root found" show NoRootFound = "No root found"
show NoCorpusFound = "No corpus found" show NoCorpusFound = "No corpus found"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment