From 0165caef2f5651231ef3cd216192f8a3a7a99b39 Mon Sep 17 00:00:00 2001 From: defanor Date: Thu, 17 Jan 2019 04:27:57 +0300 Subject: Avoid `fromJust` in `findPath` Not all the room IDs are in the database, so it occasionally led to errors. --- DWProxy.hs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/DWProxy.hs b/DWProxy.hs index 63ac880..a8d4acd 100644 --- a/DWProxy.hs +++ b/DWProxy.hs @@ -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)) $ -- cgit v1.2.3