core: print error context on agent errors (#1697)

This commit is contained in:
JRoberts
2023-01-06 13:11:21 +04:00
committed by GitHub
parent edfece3206
commit ae5deab8d3
4 changed files with 58 additions and 36 deletions
+1 -1
View File
@@ -540,7 +540,7 @@ tmeToPref currentTTL tme = uncurry TimedMessagesPreference $ case tme of
data ChatError
= ChatError {errorType :: ChatErrorType}
| ChatErrorAgent {agentError :: AgentErrorType}
| ChatErrorAgent {agentError :: AgentErrorType, connectionEntity_ :: Maybe ConnectionEntity}
| ChatErrorStore {storeError :: StoreError}
| ChatErrorDatabase {databaseError :: DatabaseError}
deriving (Show, Exception, Generic)
+22 -4
View File
@@ -1201,15 +1201,33 @@ viewChatError = \case
DBErrorExport e -> ["error encrypting database: " <> sqliteError' e]
DBErrorOpen e -> ["error opening database after encryption: " <> sqliteError' e]
e -> ["chat database error: " <> sShow e]
ChatErrorAgent err -> case err of
ChatErrorAgent err entity -> case err of
SMP SMP.AUTH ->
[ "error: connection authorization failed - this could happen if connection was deleted,\
\ secured with different credentials, or due to a bug - please re-create the connection"
[ withConnEntity
<> "error: connection authorization failed - this could happen if connection was deleted,\
\ secured with different credentials, or due to a bug - please re-create the connection"
]
AGENT A_DUPLICATE -> []
AGENT A_PROHIBITED -> []
CONN NOT_FOUND -> []
e -> ["smp agent error: " <> sShow e]
e -> [withConnEntity <> "smp agent error: " <> sShow e]
where
withConnEntity = case entity of
Just (RcvDirectMsgConnection conn contact_) -> case contact_ of
Just Contact {contactId, localDisplayName = c} ->
"[" <> ttyFrom c <> ", contactId: " <> sShow contactId <> ", connId: " <> cId conn <> "] "
Nothing ->
"[" <> ttyFrom "rcv direct msg" <> ", connId: " <> cId conn <> "] "
Just (RcvGroupMsgConnection conn g@GroupInfo {groupId} m@GroupMember {groupMemberId}) ->
"[" <> ttyFrom (fromGroup_ g m) <> ", groupId: " <> sShow groupId <> ", memberId: " <> sShow groupMemberId <> ", connId: " <> cId conn <> "] "
Just (RcvFileConnection conn RcvFileTransfer {fileId, fileInvitation = FileInvitation {fileName}}) ->
"[" <> ttyFrom ("rcv file " <> T.pack fileName) <> ", fileId: " <> sShow fileId <> ", connId: " <> cId conn <> "] "
Just (SndFileConnection conn SndFileTransfer {fileId, fileName}) ->
"[" <> ttyTo ("snd file " <> T.pack fileName) <> ", fileId: " <> sShow fileId <> ", connId: " <> cId conn <> "] "
Just (UserContactConnection conn UserContact {userContactLinkId}) ->
"[" <> ttyFrom "contact address" <> ", userContactLinkId: " <> sShow userContactLinkId <> ", connId: " <> cId conn <> "] "
Nothing -> ""
cId conn = sShow (connId (conn :: Connection))
where
fileNotFound fileId = ["file " <> sShow fileId <> " not found"]
sqliteError' = \case