Skip to content

Commit

Permalink
fix: Improved error message when route points to non-existing page (#286
Browse files Browse the repository at this point in the history
).
  • Loading branch information
Martinsos committed Jul 22, 2021
1 parent f7b203e commit 7d73f49
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions waspc/src/Generator/WebAppGenerator/RouterGenerator.hs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ module Generator.WebAppGenerator.RouterGenerator
where

import Data.Aeson (ToJSON (..), object, (.=))
import Data.Maybe (fromJust, isJust)
import Data.List (find)
import Data.Maybe (fromJust, fromMaybe, isJust)
import Generator.FileDraft (FileDraft)
import Generator.WebAppGenerator.Common (asTmplFile, asWebAppSrcFile)
import qualified Generator.WebAppGenerator.Common as C
Expand Down Expand Up @@ -92,8 +93,10 @@ determineRouteTargetComponent wasp route =
(Wasp.Page._authRequired targetPage)
where
targetPageName = Wasp.Route._targetPage route
-- NOTE(matija): if no page with the name specified in the route, head will fail.
targetPage = head $ filter ((==) targetPageName . Wasp.Page._name) (Wasp.getPages wasp)
targetPage =
fromMaybe
(error $ "Can't find page with name '" ++ targetPageName ++ "', pointed to by route '" ++ Wasp.Route._urlPath route ++ "'")
(find ((==) targetPageName . Wasp.Page._name) (Wasp.getPages wasp))

determineRouteTargetComponent' :: Bool -> String
determineRouteTargetComponent' authRequired =
Expand Down

0 comments on commit 7d73f49

Please sign in to comment.