king dawn: instead of crashing, return an error
@@ -57,11 +57,14 @@ shipSein = Ship . fromIntegral . Ob.fromPatp . Ob.sein . Ob.patp . fromIntegral
renderShip :: Ship -> Text
renderShip = Ob.renderPatp . Ob.patp . fromIntegral
-
hexStrToAtom :: Text -> Atom
hexStrToAtom =
bytesAtom . reverse . toBytes . hexString . removePrefix . encodeUtf8
+onLeft :: (a -> b) -> Either a c -> Either b c
+onLeft fun (Left a) = Left $ fun a
+onLeft fun (Right c) = Right c
+
-- Data Validation -------------------------------------------------------------
-- Derive public key structure from the key derivation seed structure
@@ -397,7 +400,9 @@ getSponsorshipChain endpoint block = loop
-- Produces either an error or a validated boot event structure.
dawnVent :: HasLogFunc e => Seed -> RIO e (Either Text Dawn)
-dawnVent dSeed@(Seed ship life ring oaf) = do
+dawnVent dSeed@(Seed ship life ring oaf) =
+ -- The type checker can't figure this out on its own.
+ (onLeft tshow :: Either SomeException Dawn -> Either Text Dawn) <$> try do
blockResponses
<- dawnPostRequests provider parseBlockRequest [BlockRequest]
@@ -422,9 +427,7 @@ dawnVent dSeed@(Seed ship life ring oaf) = do
let dNode = Nothing
- -- TODO: Figure out exception handling now. We don't want all the `error`
- -- statements in ehre to literally kill the program.
- pure $ Right $ MkDawn{..}
+ pure $ MkDawn{..}
-- Comet List ------------------------------------------------------------------
