1
1
mirror of https://github.com/aelve/guide.git synced 2025-01-01 18:14:21 +03:00

Add error messages for *ById lenses

This commit is contained in:
Artyom 2016-04-07 18:07:04 +03:00
parent 5827fb5b1a
commit 358c8c769f

View File

@ -108,6 +108,7 @@ import Lens.Micro.Platform
import qualified Data.Map as M import qualified Data.Map as M
import Data.Map (Map) import Data.Map (Map)
-- Text -- Text
import qualified Data.Text as T
import Data.Text (Text) import Data.Text (Text)
-- Time -- Time
import Data.Time import Data.Time
@ -538,21 +539,29 @@ addGroupIfDoesNotExist g gs
traitById :: Uid -> Lens' Item Trait traitById :: Uid -> Lens' Item Trait
traitById uid' = singular $ traitById uid' = singular $
(pros.each . filtered ((== uid') . view uid)) `failing` (pros.each . filtered ((== uid') . view uid)) `failing`
(cons.each . filtered ((== uid') . view uid)) (cons.each . filtered ((== uid') . view uid)) `failing`
error ("traitById: couldn't find trait with uid " ++
T.unpack (uidToText uid'))
categoryById :: Uid -> Lens' GlobalState Category categoryById :: Uid -> Lens' GlobalState Category
categoryById catId = singular $ categoryById catId = singular $
categories.each . filtered ((== catId) . view uid) categories.each . filtered ((== catId) . view uid) `failing`
error ("categoryById: couldn't find category with uid " ++
T.unpack (uidToText catId))
categoryByItem :: Uid -> Lens' GlobalState Category categoryByItem :: Uid -> Lens' GlobalState Category
categoryByItem itemId = singular $ categoryByItem itemId = singular $
categories.each . filtered hasItem categories.each . filtered hasItem `failing`
error ("categoryByItem: couldn't find category with item with uid " ++
T.unpack (uidToText itemId))
where where
hasItem category = itemId `elem` (category^..items.each.uid) hasItem category = itemId `elem` (category^..items.each.uid)
itemById :: Uid -> Lens' GlobalState Item itemById :: Uid -> Lens' GlobalState Item
itemById itemId = singular $ itemById itemId = singular $
categories.each . items.each . filtered ((== itemId) . view uid) categories.each . items.each . filtered ((== itemId) . view uid) `failing`
error ("itemById: couldn't find item with uid " ++
T.unpack (uidToText itemId))
-- get -- get