@@ -33,19 +33,19 @@ import Database.PostgreSQL.Driver.RawConnection
33
33
34
34
-- | Public
35
35
-- Connection parametrized by message type in chan.
36
- data AbsConnection msg = AbsConnection
36
+ data AbsConnection mt = AbsConnection
37
37
{ connRawConnection :: RawConnection
38
38
, connReceiverThread :: Weak ThreadId
39
39
, connStatementStorage :: StatementStorage
40
40
, connParameters :: ConnectionParameters
41
- , connOutChan :: OutChan msg
41
+ , connOutChan :: OutChan ( Either ReceiverException mt )
42
42
}
43
43
44
- type Connection = AbsConnection ( Either Error DataRows )
45
- type ConnectionCommon = AbsConnection ( Either Error ServerMessage )
44
+ type Connection = AbsConnection DataMessage
45
+ type ConnectionCommon = AbsConnection ServerMessage
46
46
47
- type InDataChan = InChan (Either Error DataRows )
48
- type InAllChan = InChan (Either Error ServerMessage )
47
+ type InDataChan = InChan (Either ReceiverException DataMessage )
48
+ type InAllChan = InChan (Either ReceiverException ServerMessage )
49
49
50
50
-- | Parameters of the current connection.
51
51
-- We store only the parameters that cannot change after startup.
@@ -77,7 +77,6 @@ connect :: ConnectionSettings -> IO (Either Error Connection)
77
77
connect settings = connectWith settings $ \ rawConn params ->
78
78
buildConnection rawConn params
79
79
(receiverThread rawConn)
80
- (Left . UnexpectedError )
81
80
82
81
connectCommon
83
82
:: ConnectionSettings
@@ -94,7 +93,6 @@ connectCommon' settings msgFilter = connectWith settings $ \rawConn params ->
94
93
buildConnection rawConn params
95
94
(\ chan -> receiverThreadCommon rawConn chan
96
95
msgFilter defaultNotificationHandler)
97
- (Left . UnexpectedError )
98
96
99
97
connectWith
100
98
:: ConnectionSettings
@@ -142,7 +140,9 @@ authorize rawConn settings = do
142
140
throwAuthErrorInIO $ AuthNotSupported " GSS"
143
141
AuthErrorResponse desc ->
144
142
throwErrorInIO $ PostgresError desc
145
- Left reason -> throwErrorInIO . DecodeError $ BS. pack reason
143
+ Left reason -> error " handle error here"
144
+ -- TODO handle errors
145
+ -- throwErrorInIO . DecodeError $ BS.pack reason
146
146
147
147
performPasswordAuth password = do
148
148
sendMessage rawConn $ PasswordMessage password
@@ -158,18 +158,15 @@ buildConnection
158
158
:: RawConnection
159
159
-> ConnectionParameters
160
160
-- action in receiver thread
161
- -> (InChan c -> IO () )
162
- -- transform exception to message to inform the other thread
163
- -- about unexpected error
164
- -> (SomeException -> c )
161
+ -> (InChan (Either ReceiverException c ) -> IO () )
165
162
-> IO (AbsConnection c )
166
- buildConnection rawConn connParams receiverAction transformExc = do
163
+ buildConnection rawConn connParams receiverAction = do
167
164
(inChan, outChan) <- newChan
168
165
storage <- newStatementStorage
169
166
170
167
let createReceiverThread = mask_ $ forkIOWithUnmask $ \ unmask ->
171
168
unmask (receiverAction inChan)
172
- `catch` (writeChan inChan . transformExc )
169
+ `catch` (writeChan inChan . Left . ReceiverException )
173
170
174
171
-- When receiver thread dies by any unexpected exception, than message
175
172
-- would be written in its chan.
@@ -189,7 +186,8 @@ buildConnection rawConn connParams receiverAction transformExc = do
189
186
parseParameters :: B. ByteString -> Either Error ConnectionParameters
190
187
parseParameters str = do
191
188
dict <- go str HM. empty
192
- serverVersion <- maybe (Left $ DecodeError " server version" ) Right .
189
+ -- TODO handle error
190
+ serverVersion <- maybe (error " handle error" ) Right .
193
191
parseServerVersion =<< lookupKey " server_version" dict
194
192
serverEncoding <- lookupKey " server_encoding" dict
195
193
integerDatetimes <- parseIntegerDatetimes <$>
@@ -201,7 +199,8 @@ parseParameters str = do
201
199
}
202
200
where
203
201
lookupKey key = maybe
204
- (Left . DecodeError $ " Missing connection parameter " <> key ) Right
202
+ -- TODO
203
+ (error " handle errors" ) Right
205
204
. HM. lookup key
206
205
go str dict | B. null str = Right dict
207
206
| otherwise = case runDecode
@@ -210,7 +209,9 @@ parseParameters str = do
210
209
ParameterStatus name value -> go rest $ HM. insert name value dict
211
210
-- messages like `BackendData` not handled
212
211
_ -> go rest dict
213
- Left reason -> Left . DecodeError $ BS. pack reason
212
+ Left reason -> error " handle error here"
213
+ -- TODO
214
+ -- Left . DecodeError $ BS.pack reason
214
215
215
216
handshakeTls :: RawConnection -> IO ()
216
217
handshakeTls _ = pure ()
0 commit comments