diff options
author | defanor <defanor@uberspace.net> | 2019-01-17 04:27:57 +0300 |
---|---|---|
committer | defanor <defanor@uberspace.net> | 2019-01-17 04:27:57 +0300 |
commit | 0165caef2f5651231ef3cd216192f8a3a7a99b39 (patch) | |
tree | 340b6971727903afffa395ce509e0882bea300f4 | |
parent | 6f13487eeb6e001d7b9e4b9311b8b719407bcd5a (diff) |
Avoid `fromJust` in `findPath`
Not all the room IDs are in the database, so it occasionally led to
errors.
-rw-r--r-- | DWProxy.hs | 9 |
1 files changed, 5 insertions, 4 deletions
@@ -8,7 +8,7 @@ import Data.Graph.Inductive.PatriciaTree (Gr) import Data.Graph.Inductive.Query.SP (sp) import qualified Data.HashMap.Strict as HM import qualified Database.SQLite.Simple as SQLite -import Data.Maybe (mapMaybe, fromJust) +import Data.Maybe (mapMaybe) import System.Environment (getArgs) import System.FilePath ((</>)) import Network.Socket.ByteString (sendAll, recv) @@ -105,9 +105,10 @@ pathFinder rooms exits = findPath :: PathFinder -> RoomID -> RoomID -> Either T.Text [T.Text] findPath pf from to = - let route = sp (fromJust $ HM.lookup from $ pfRoomToNode pf) - (fromJust $ HM.lookup to $ pfRoomToNode pf) - (pfGraph pf) + let route = case ( HM.lookup from $ pfRoomToNode pf + , HM.lookup to $ pfRoomToNode pf) of + (Just f, Just t) -> sp f t (pfGraph pf) + _ -> Nothing in case route of Just path@(_:_) -> Right $ mapMaybe (flip HM.lookup (pfExitMap pf)) $ |