add proper error types

This commit is contained in:
Alain Brenzikofer committed 2026-08-18 17:12:17 +02:00
1 parent 58916c0303
commit 31909213b4
7 files changed
+28 -7

No files matched your search

+3
View File
@@ -1471,6 +1471,9 @@ data ChatErrorType
| CEChatStoreChanged
| CEInvalidConnReq
| CESimplexDomainNotReady {simplexDomain :: SimplexDomain, simplexDomainError :: SimplexDomainError}
-- | the names service refused the registration; @nameRegCode@ is the protocol
-- error code as sent on the wire, e.g. @name_taken@
| CENameRegistrationFailed {nameRegCode :: Text, nameRegMessage :: Maybe Text}
| CENotResolvedLocally -- a name or link is not a known chat in the local store and online resolution is off (PRMNever)
| CEUnsupportedConnReq
| CEInvalidChatMessage {connection :: Connection, msgMeta :: Maybe MsgMetaJSON, messageData :: Text, message :: String}
+2 -4
View File
@@ -1479,7 +1479,7 @@ processChatCommand cxt nm = \case
progress NRPhaseCommitting Nothing
sendNames (NRCommit commitment) >>= \case
NRPCommitted {} -> pure ()
NRPError {nrCode, nrMessage} -> throwCmdError $ nameRegError nrCode nrMessage
NRPError {nrCode, nrMessage} -> throwChatError $ CENameRegistrationFailed (textEncode nrCode) nrMessage
_ -> throwCmdError "unexpected commit response"
progress NRPhaseCommitted (Just commitWaitMs)
liftIO $ threadDelay $ fromIntegral commitWaitMs * 1000
@@ -1487,7 +1487,7 @@ processChatCommand cxt nm = \case
(expiry', txHash') <-
sendNames (NRReveal nm' owner secret ttl sLink) >>= \case
NRPRegistered {nrExpiry, nrTxHash} -> pure (nrExpiry, nrTxHash)
NRPError {nrCode, nrMessage} -> throwCmdError $ nameRegError nrCode nrMessage
NRPError {nrCode, nrMessage} -> throwChatError $ CENameRegistrationFailed (textEncode nrCode) nrMessage
_ -> throwCmdError "unexpected reveal response"
progress NRPhaseRegistered Nothing
pure $ CRNameRegistered user nm' (tshow owner) expiry' txHash'
@@ -1499,8 +1499,6 @@ processChatCommand cxt nm = \case
(seed, AccountRef {arIndex}) <-
withFastStore' $ \db -> getOrCreateAccountRef db user (atomically $ newSeed MS256 g)
either (throwCmdError . ("wallet: " <>)) (pure . accountAddress) $ deriveAccount seed arIndex
nameRegError code message =
"name registration failed: " <> T.unpack (textEncode code) <> maybe "" ((": " <>) . T.unpack) message
APISendServiceResponse userId requestId responseData -> withUserId userId $ \user -> do
let AgentInvId invId = requestId
connId <- withAgent $ \a -> sendServiceReplyAsync a "" (aUserId user) invId (LB.toStrict $ J.encode responseData)
+1
View File
@@ -2806,6 +2806,7 @@ viewChatError isCmd logLevel testView = \case
CEAgentNoSubResult connId -> ["no subscription result for connection: " <> sShow connId]
CEServerProtocol p -> [plain $ "Servers for protocol " <> strEncode p <> " cannot be configured by the users"]
CECommandError e -> ["bad chat command: " <> plain e]
CENameRegistrationFailed code msg -> ["name registration failed: " <> plain code <> maybe "" ((": " <>) . plain) msg]
CEAgentCommandError e -> ["agent command error: " <> plain e]
CEInvalidFileDescription e -> ["invalid file description: " <> plain e]
CEConnectionIncognitoChangeProhibited -> ["incognito mode change prohibited"]