Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

subworlds #1353

Merged
merged 25 commits into from
Jul 22, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
use failT in more places
  • Loading branch information
kostmo committed Jul 21, 2023
commit 743f755d18e49044791562ac8c57b088612b09f0
25 changes: 11 additions & 14 deletions src/Swarm/Game/Scenario/Topography/Navigation/Portal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -191,15 +191,13 @@ validatePortals (Navigation wpUniverse partialPortals) = do
subworldWaypoints <- case M.lookup swName wpUniverse of
Just x -> return x
Nothing ->
fail $
T.unpack $
T.unwords
[ "Could not lookup waypoint"
, quote exitName
, "for portal exit because subworld"
, quote $ renderWorldName swName
, "does not exist"
]
failT
[ "Could not lookup waypoint"
, quote exitName
, "for portal exit because subworld"
, quote $ renderWorldName swName
, "does not exist"
]

failWaypointLookup wpWrapper $
M.lookup wpWrapper subworldWaypoints
Expand All @@ -224,11 +222,10 @@ ensureSpatialConsistency ::
m ()
ensureSpatialConsistency xs =
kostmo marked this conversation as resolved.
Show resolved Hide resolved
unless (null nonUniform) $
fail $
unwords
[ "Non-uniform portal distances:"
, show nonUniform
]
failT
[ "Non-uniform portal distances:"
, showT nonUniform
]
where
consistentPairs :: [(Cosmic Location, Cosmic Location)]
consistentPairs = map (fmap cosmoLocation) $ filter (enforceConsistency . snd) xs
Expand Down
3 changes: 2 additions & 1 deletion src/Swarm/Game/Scenario/Topography/Structure.hs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import Swarm.Game.Scenario.Topography.Cell
import Swarm.Game.Scenario.Topography.Navigation.Waypoint
import Swarm.Game.Scenario.Topography.Placement
import Swarm.Game.Scenario.Topography.WorldPalette
import Swarm.Util (failT, showT)
import Swarm.Util.Yaml
import Witch (into)

Expand Down Expand Up @@ -144,7 +145,7 @@ paintMap maskChar pal a = do
if Just c == maskChar
then return Nothing
else case KeyMap.lookup (Key.fromString [c]) (unPalette pal) of
Nothing -> fail $ "Char not in world palette: " ++ show c
Nothing -> failT ["Char not in world palette:", showT c]
Just cell -> return $ Just cell

readMap :: Applicative f => (Char -> f b) -> Text -> f [[b]]
Expand Down
3 changes: 2 additions & 1 deletion src/Swarm/TUI/Model.hs
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ import Swarm.TUI.Model.Menu
import Swarm.TUI.Model.Name
import Swarm.TUI.Model.Repl
import Swarm.TUI.Model.UI
import Swarm.Util (failT, showT)
import Swarm.Util.Lens (makeLensesNoSigs)
import Swarm.Version (NewReleaseFailure (NoMainUpstreamRelease))
import Text.Fuzzy qualified as Fuzzy
Expand Down Expand Up @@ -208,7 +209,7 @@ initRuntimeState = do
namesFile <- getDataFileNameSafe NameGeneration "names.txt"
return (adjsFile, namesFile)

let markEx what a = catchError a (\e -> fail $ "Failed to " <> what <> ": " <> show e)
let markEx what a = catchError a (\e -> failT ["Failed to", what <> ":", showT e])
(adjs, names) <- liftIO . markEx "load name generation data" $ do
as <- tail . T.lines <$> T.readFile adjsFile
ns <- tail . T.lines <$> T.readFile namesFile
Expand Down
4 changes: 3 additions & 1 deletion src/Swarm/Version.hs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import Data.Char (isDigit)
import Data.Either (lefts, rights)
import Data.Foldable (toList)
import Data.Maybe (listToMaybe)
import Data.Text qualified as T
import Data.Version (Version (..), parseVersion, showVersion)
import Data.Yaml (ParseException, Parser, decodeEither', parseEither)
import GitHash (GitInfo, giBranch)
Expand All @@ -38,6 +39,7 @@ import Network.HTTP.Client (
import Network.HTTP.Client.TLS (tlsManagerSettings)
import Network.HTTP.Types (hUserAgent)
import Paths_swarm qualified
import Swarm.Util (failT, quote)
import Text.ParserCombinators.ReadP (readP_to_S)

-- $setup
Expand Down Expand Up @@ -104,7 +106,7 @@ parseRelease = \case
t <- o .: "tag_name"
if isSwarmReleaseTag t
then return t
else fail $ "The release '" <> t <> "' is not main Swarm release!"
else failT ["The release", quote $ T.pack t, "is not main Swarm release!"]
_otherValue -> fail "The JSON release is not an Object!"

data NewReleaseFailure where
Expand Down