mirror of
https://github.com/simplex-chat/simplex-chat.git
synced 2026-05-25 09:54:22 +00:00
core: extended network errors information (simplexmq) (#6247)
* core: extended network errors information (simplexmq) * fix test * docs: add NetworkError to bot API types * update simplexmq - JSON encoding for missing NetworkError
This commit is contained in:
@@ -66,7 +66,7 @@ crDirectoryEvent :: Either ChatError ChatEvent -> Maybe DirectoryEvent
|
||||
crDirectoryEvent = \case
|
||||
Right evt -> crDirectoryEvent_ evt
|
||||
Left e -> case e of
|
||||
ChatErrorAgent {agentError = BROKER _ NETWORK} -> Nothing
|
||||
ChatErrorAgent {agentError = BROKER _ (NETWORK _)} -> Nothing
|
||||
ChatErrorAgent {agentError = BROKER _ TIMEOUT} -> Nothing
|
||||
_ -> Just $ DELogChatResponse $ "chat error: " <> tshow e
|
||||
|
||||
|
||||
@@ -121,6 +121,7 @@ This file is generated automatically.
|
||||
- [MsgFilter](#msgfilter)
|
||||
- [MsgReaction](#msgreaction)
|
||||
- [MsgReceiptStatus](#msgreceiptstatus)
|
||||
- [NetworkError](#networkerror)
|
||||
- [NewUser](#newuser)
|
||||
- [NoteFolder](#notefolder)
|
||||
- [PendingContactConnection](#pendingcontactconnection)
|
||||
@@ -343,6 +344,7 @@ UNEXPECTED:
|
||||
|
||||
NETWORK:
|
||||
- type: "NETWORK"
|
||||
- networkError: [NetworkError](#networkerror)
|
||||
|
||||
HOST:
|
||||
- type: "HOST"
|
||||
@@ -2635,6 +2637,34 @@ Unknown:
|
||||
- "badMsgHash"
|
||||
|
||||
|
||||
---
|
||||
|
||||
## NetworkError
|
||||
|
||||
**Discriminated union type**:
|
||||
|
||||
ConnectError:
|
||||
- type: "connectError"
|
||||
- connectError: string
|
||||
|
||||
TLSError:
|
||||
- type: "tLSError"
|
||||
- tlsError: string
|
||||
|
||||
UnknownCAError:
|
||||
- type: "unknownCAError"
|
||||
|
||||
FailedError:
|
||||
- type: "failedError"
|
||||
|
||||
TimeoutError:
|
||||
- type: "timeoutError"
|
||||
|
||||
SubscribeError:
|
||||
- type: "subscribeError"
|
||||
- subscribeError: string
|
||||
|
||||
|
||||
---
|
||||
|
||||
## NewUser
|
||||
|
||||
@@ -42,7 +42,7 @@ import Simplex.Messaging.Agent.Protocol
|
||||
import Simplex.Messaging.Client
|
||||
import Simplex.Messaging.Crypto.File
|
||||
import Simplex.Messaging.Parsers (dropPrefix, fstToLower)
|
||||
import Simplex.Messaging.Protocol (BlockingInfo (..), BlockingReason (..), CommandError (..), ErrorType (..), ProxyError (..))
|
||||
import Simplex.Messaging.Protocol (BlockingInfo (..), BlockingReason (..), CommandError (..), ErrorType (..), NetworkError (..), ProxyError (..))
|
||||
import Simplex.Messaging.Transport
|
||||
import Simplex.RemoteControl.Types
|
||||
import System.Console.ANSI.Types (Color (..))
|
||||
@@ -299,6 +299,7 @@ chatTypesDocsData =
|
||||
(sti @MsgFilter, STEnum, "MF", [], "", ""),
|
||||
(sti @MsgReaction, STUnion, "MR", [], "", ""),
|
||||
(sti @MsgReceiptStatus, STEnum, "MR", [], "", ""),
|
||||
(sti @NetworkError, STUnion, "NE", [], "", ""),
|
||||
(sti @NewUser, STRecord, "", [], "", ""),
|
||||
(sti @NoteFolder, STRecord, "", [], "", ""),
|
||||
(sti @PendingContactConnection, STRecord, "", [], "", ""),
|
||||
@@ -492,6 +493,7 @@ deriving instance Generic MsgErrorType
|
||||
deriving instance Generic MsgFilter
|
||||
deriving instance Generic MsgReaction
|
||||
deriving instance Generic MsgReceiptStatus
|
||||
deriving instance Generic NetworkError
|
||||
deriving instance Generic NewUser
|
||||
deriving instance Generic NoteFolder
|
||||
deriving instance Generic PendingContactConnection
|
||||
|
||||
+1
-1
@@ -12,7 +12,7 @@ constraints: zip +disable-bzip2 +disable-zstd
|
||||
source-repository-package
|
||||
type: git
|
||||
location: https://github.com/simplex-chat/simplexmq.git
|
||||
tag: 0319addd2b6bcd1206921c844f81fea4adc791a4
|
||||
tag: 2a61085f078417c6a0767d3e2d8162bac83c963c
|
||||
|
||||
source-repository-package
|
||||
type: git
|
||||
|
||||
@@ -216,6 +216,7 @@ export namespace BrokerErrorType {
|
||||
|
||||
export interface NETWORK extends Interface {
|
||||
type: "NETWORK"
|
||||
networkError: NetworkError
|
||||
}
|
||||
|
||||
export interface HOST extends Interface {
|
||||
@@ -2915,6 +2916,55 @@ export enum MsgReceiptStatus {
|
||||
BadMsgHash = "badMsgHash",
|
||||
}
|
||||
|
||||
export type NetworkError =
|
||||
| NetworkError.ConnectError
|
||||
| NetworkError.TLSError
|
||||
| NetworkError.UnknownCAError
|
||||
| NetworkError.FailedError
|
||||
| NetworkError.TimeoutError
|
||||
| NetworkError.SubscribeError
|
||||
|
||||
export namespace NetworkError {
|
||||
export type Tag =
|
||||
| "connectError"
|
||||
| "tLSError"
|
||||
| "unknownCAError"
|
||||
| "failedError"
|
||||
| "timeoutError"
|
||||
| "subscribeError"
|
||||
|
||||
interface Interface {
|
||||
type: Tag
|
||||
}
|
||||
|
||||
export interface ConnectError extends Interface {
|
||||
type: "connectError"
|
||||
connectError: string
|
||||
}
|
||||
|
||||
export interface TLSError extends Interface {
|
||||
type: "tLSError"
|
||||
tlsError: string
|
||||
}
|
||||
|
||||
export interface UnknownCAError extends Interface {
|
||||
type: "unknownCAError"
|
||||
}
|
||||
|
||||
export interface FailedError extends Interface {
|
||||
type: "failedError"
|
||||
}
|
||||
|
||||
export interface TimeoutError extends Interface {
|
||||
type: "timeoutError"
|
||||
}
|
||||
|
||||
export interface SubscribeError extends Interface {
|
||||
type: "subscribeError"
|
||||
subscribeError: string
|
||||
}
|
||||
}
|
||||
|
||||
export interface NewUser {
|
||||
profile?: Profile
|
||||
pastTimestamp: boolean
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"https://github.com/simplex-chat/simplexmq.git"."0319addd2b6bcd1206921c844f81fea4adc791a4" = "1rm0m6bch648xpa8l28m3ww6fi686g9ky68qc46gsqirpm29kh0q";
|
||||
"https://github.com/simplex-chat/simplexmq.git"."2a61085f078417c6a0767d3e2d8162bac83c963c" = "1zqssgz9d3bydcrnqlfy6aj7hfi65wb1mjcjpl3q744s82lrj68w";
|
||||
"https://github.com/simplex-chat/hs-socks.git"."a30cc7a79a08d8108316094f8f2f82a0c5e1ac51" = "0yasvnr7g91k76mjkamvzab2kvlb1g5pspjyjn2fr6v83swjhj38";
|
||||
"https://github.com/simplex-chat/direct-sqlcipher.git"."f814ee68b16a9447fbb467ccc8f29bdd3546bfd9" = "1ql13f4kfwkbaq7nygkxgw84213i0zm7c1a8hwvramayxl38dq5d";
|
||||
"https://github.com/simplex-chat/sqlcipher-simple.git"."a46bd361a19376c5211f1058908fc0ae6bf42446" = "1z0r78d8f0812kxbgsm735qf6xx8lvaz27k1a0b4a2m0sshpd5gl";
|
||||
|
||||
@@ -4243,7 +4243,7 @@ subscribeUserConnections vr onlyNeeded agentBatchSubscribe user = do
|
||||
netStatus = maybe NSConnected $ NSError . errorNetworkStatus
|
||||
errorNetworkStatus :: ChatError -> String
|
||||
errorNetworkStatus = \case
|
||||
ChatErrorAgent (BROKER _ NETWORK) _ -> "network"
|
||||
ChatErrorAgent (BROKER _ (NETWORK _)) _ -> "network"
|
||||
ChatErrorAgent (SMP _ SMP.AUTH) _ -> "contact deleted"
|
||||
e -> show e
|
||||
-- TODO possibly below could be replaced with less noisy events for API
|
||||
|
||||
@@ -1601,7 +1601,7 @@ processAgentMessageConn vr user@User {userId} corrId agentConnId agentMessage =
|
||||
e -> SndErrOther $ tshow e
|
||||
where
|
||||
brokerError srvErr = \case
|
||||
NETWORK -> SndErrExpired
|
||||
NETWORK _ -> SndErrExpired
|
||||
TIMEOUT -> SndErrExpired
|
||||
HOST -> srvErr SrvErrHost
|
||||
SMP.TRANSPORT TEVersion -> srvErr SrvErrVersion
|
||||
|
||||
@@ -68,7 +68,7 @@ import qualified Simplex.Messaging.Crypto.Ratchet as CR
|
||||
import Simplex.Messaging.Encoding
|
||||
import Simplex.Messaging.Encoding.String
|
||||
import Simplex.Messaging.Parsers (dropPrefix, taggedObjectJSON)
|
||||
import Simplex.Messaging.Protocol (AProtoServerWithAuth (..), AProtocolType, BlockingInfo (..), BlockingReason (..), ProtocolServer (..), ProtocolTypeI, SProtocolType (..), UserProtocol)
|
||||
import Simplex.Messaging.Protocol (AProtoServerWithAuth (..), AProtocolType, BlockingInfo (..), BlockingReason (..), NetworkError (..), ProtocolServer (..), ProtocolTypeI, SProtocolType (..), UserProtocol)
|
||||
import qualified Simplex.Messaging.Protocol as SMP
|
||||
import Simplex.Messaging.Transport.Client (TransportHost (..))
|
||||
import Simplex.Messaging.Util (safeDecodeUtf8, tshow)
|
||||
@@ -1515,11 +1515,11 @@ viewServerTestResult (AProtoServerWithAuth p _) = \case
|
||||
result
|
||||
<> [pName <> " server requires authorization to create queues, check password" | testStep == TSCreateQueue && (case testError of SMP _ SMP.AUTH -> True; _ -> False)]
|
||||
<> [pName <> " server requires authorization to upload files, check password" | testStep == TSCreateFile && (case testError of XFTP _ XFTP.AUTH -> True; _ -> False)]
|
||||
<> ["Possibly, certificate fingerprint in " <> pName <> " server address is incorrect" | testStep == TSConnect && brokerErr]
|
||||
<> ["Certificate fingerprint in " <> pName <> " server address does not match server certificate" | testStep == TSConnect && unknownCA]
|
||||
where
|
||||
result = [pName <> " server test failed at " <> plain (drop 2 $ show testStep) <> ", error: " <> sShow testError]
|
||||
brokerErr = case testError of
|
||||
BROKER _ NETWORK -> True
|
||||
unknownCA = case testError of
|
||||
BROKER _ (NETWORK NEUnknownCAError) -> True
|
||||
_ -> False
|
||||
_ -> [pName <> " server test passed"]
|
||||
where
|
||||
@@ -2546,7 +2546,7 @@ viewChatError isCmd logLevel testView = \case
|
||||
reasonStr = case reason of
|
||||
BRSpam -> "spam"
|
||||
BRContent -> "content violates conditions of use"
|
||||
BROKER _ NETWORK | not isCmd -> []
|
||||
BROKER _ (NETWORK _) | not isCmd -> []
|
||||
BROKER _ TIMEOUT | not isCmd -> []
|
||||
AGENT A_DUPLICATE -> [withConnEntity <> "error: AGENT A_DUPLICATE" | logLevel == CLLDebug || isCmd]
|
||||
AGENT (A_PROHIBITED e) -> [withConnEntity <> "error: AGENT A_PROHIBITED, " <> plain e | logLevel <= CLLWarning || isCmd]
|
||||
|
||||
@@ -1161,8 +1161,8 @@ testTestSMPServerConnection =
|
||||
alice ##> "/smp test smp://LcJUMfVhwD8yxjAiSaDzzGF3-kLG4Uh0Fl_ZIjrRwjI=:server_password@localhost:7001"
|
||||
alice <## "SMP server test passed"
|
||||
alice ##> "/smp test smp://LcJU@localhost:7001"
|
||||
alice <## "SMP server test failed at Connect, error: BROKER {brokerAddress = \"smp://LcJU@localhost:7001\", brokerErr = NETWORK}"
|
||||
alice <## "Possibly, certificate fingerprint in SMP server address is incorrect"
|
||||
alice <## "SMP server test failed at Connect, error: BROKER {brokerAddress = \"smp://LcJU@localhost:7001\", brokerErr = NETWORK {networkError = NEUnknownCAError}}"
|
||||
alice <## "Certificate fingerprint in SMP server address does not match server certificate"
|
||||
|
||||
testGetSetXFTPServers :: HasCallStack => TestParams -> IO ()
|
||||
testGetSetXFTPServers =
|
||||
@@ -1203,8 +1203,8 @@ testTestXFTPServer =
|
||||
alice ##> "/xftp test xftp://LcJUMfVhwD8yxjAiSaDzzGF3-kLG4Uh0Fl_ZIjrRwjI=:server_password@localhost:7002"
|
||||
alice <## "XFTP server test passed"
|
||||
alice ##> "/xftp test xftp://LcJU@localhost:7002"
|
||||
alice <## "XFTP server test failed at Connect, error: BROKER {brokerAddress = \"xftp://LcJU@localhost:7002\", brokerErr = NETWORK}"
|
||||
alice <## "Possibly, certificate fingerprint in XFTP server address is incorrect"
|
||||
alice <## "XFTP server test failed at Connect, error: BROKER {brokerAddress = \"xftp://LcJU@localhost:7002\", brokerErr = NETWORK {networkError = NEUnknownCAError}}"
|
||||
alice <## "Certificate fingerprint in XFTP server address does not match server certificate"
|
||||
|
||||
testOperators :: HasCallStack => TestParams -> IO ()
|
||||
testOperators =
|
||||
|
||||
Reference in New Issue
Block a user