Skip to content

Commit 8f480ad

Browse files
committed
connection handler: renamed HandleError as HandlerError
This exception is not just used when a `Handle` is created but also when the connection handler is running.
1 parent b9bcc88 commit 8f480ad

File tree

10 files changed

+63
-58
lines changed

10 files changed

+63
-58
lines changed

ouroboros-network-framework/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
### Breaking changes
66

7+
* `HandleError` renamed as `HandlerError`, also `HandlerErrorType` and `classifyHandlerError`.
8+
79
### Non-breaking changes
810

911
## 0.19.0.0 -- 28.06.2025

ouroboros-network-framework/demo/connection-manager.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ withBidirectionalConnectionManager snocket makeBearer socket
280280
},
281281
updateVersionData = \a _ -> a,
282282
connStateIdSupply,
283-
classifyHandleError = (\_ -> HandshakeFailure)
283+
classifyHandlerError = (\_ -> HandshakeFailure)
284284
}
285285
(InResponderMode inbgovInfoChannel)
286286
connectionHandler
@@ -566,7 +566,7 @@ bidirectionalExperiment
566566
(HandleWithExpandedCtx
567567
Mux.InitiatorResponderMode peerAddr
568568
UnversionedProtocolData ByteString IO () ())
569-
(HandleError
569+
(HandlerError
570570
UnversionedProtocol))
571571
connect n cm | n <= 1 =
572572
acquireOutboundConnection cm InitiatorAndResponderDiffusionMode remoteAddr

ouroboros-network-framework/sim-tests/Test/Ouroboros/Network/ConnectionManager.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -784,7 +784,7 @@ prop_valid_transitions (Fixed rnd) (SkewedBool bindToLocalAddress) scheduleMap =
784784
outboundIdleTimeout = testOutboundIdleTimeout,
785785
updateVersionData = \a _ -> a,
786786
connStateIdSupply,
787-
classifyHandleError = \_ -> HandshakeFailure }
787+
classifyHandlerError = \_ -> HandshakeFailure }
788788
(InResponderMode inbgovInfoChannel)
789789
connectionHandler
790790
$ \(connectionManager

ouroboros-network-framework/src/Ouroboros/Network/ConnectionHandler.hs

Lines changed: 35 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ module Ouroboros.Network.ConnectionHandler
3131
( Handle (..)
3232
, HandleWithExpandedCtx
3333
, HandleWithMinimalCtx
34-
, HandleError (..)
35-
, classifyHandleError
34+
, HandlerError (..)
35+
, classifyHandlerError
3636
, MkMuxConnectionHandler (..)
3737
, MuxConnectionHandler
3838
, makeConnectionHandler
@@ -110,7 +110,7 @@ sduHandshakeTimeout = 10
110110
-- * 'HandleHandshakeServerError'
111111
-- - the connection handler thread was running server side of the
112112
-- handshake protocol, which fail with 'HandshakeException'
113-
-- * 'HandleError'
113+
-- * 'HandlerError'
114114
-- - the multiplexer thrown 'MuxError'.
115115
--
116116
data Handle (muxMode :: Mx.Mode) initiatorCtx responderCtx versionData bytes m a b =
@@ -155,48 +155,46 @@ type HandleWithMinimalCtx muxMode peerAddr versionData bytes m a b =
155155
(ResponderContext peerAddr)
156156
versionData bytes m a b
157157

158-
data HandleError versionNumber where
159-
HandleHandshakeClientError
160-
:: !(HandshakeException versionNumber)
161-
-> HandleError versionNumber
162-
163-
HandleHandshakeServerError
164-
:: !(HandshakeException versionNumber)
165-
-> HandleError versionNumber
158+
-- | A connection handler error.
159+
--
160+
-- It is returned either when creating the `Handle` or raised by the connection
161+
-- handler.
162+
--
163+
data HandlerError versionNumber =
164+
-- | A handshake exception when creating `Handle`.
165+
HandleHandshakeClientError !(HandshakeException versionNumber)
166166

167-
HandleError
168-
:: !SomeException
169-
-> HandleError versionNumber
167+
-- | A handshake exception when creating `Handle`.
168+
| HandleHandshakeServerError !(HandshakeException versionNumber)
170169

171-
instance Show versionNumber
172-
=> Show (HandleError versionNumber) where
173-
show (HandleHandshakeServerError err) = "HandleHandshakeServerError " ++ show err
174-
show (HandleHandshakeClientError err) = "HandleHandshakeClientError " ++ show err
175-
show (HandleError err) = "HandleError " ++ show err
170+
-- | A connection handler exception (e.g. might be a mini-protocol error, io
171+
-- exception, etc).
172+
| HandlerError !SomeException
173+
deriving Show
176174

177175
instance ( Typeable versionNumber
178176
, Show versionNumber
179177
)
180-
=> Exception (HandleError versionNumber) where
181-
displayException (HandleHandshakeClientError err) = "handshake client error: " ++ displayException err
182-
displayException (HandleHandshakeServerError err) = "handshake server error: " ++ displayException err
183-
displayException (HandleError err) = show err
178+
=> Exception (HandlerError versionNumber) where
179+
displayException (HandleHandshakeClientError err) = "handshake client error: " ++ show err
180+
displayException (HandleHandshakeServerError err) = "handshake server error: " ++ show err
181+
displayException (HandlerError err) = "connection handler error: " ++ show err
184182

185183

186-
classifyHandleError :: HandleError versionNumber
187-
-> HandleErrorType
188-
classifyHandleError (HandleHandshakeClientError (HandshakeProtocolLimit _)) =
184+
classifyHandlerError :: HandlerError versionNumber
185+
-> HandlerErrorType
186+
classifyHandlerError (HandleHandshakeClientError (HandshakeProtocolLimit _)) =
189187
HandshakeProtocolViolation
190188
-- TODO: 'HandshakeProtocolError' is not a protocol error! It is just
191189
-- a negotiation failure. It should be renamed.
192-
classifyHandleError (HandleHandshakeClientError (HandshakeProtocolError _)) =
190+
classifyHandlerError (HandleHandshakeClientError (HandshakeProtocolError _)) =
193191
HandshakeFailure
194-
classifyHandleError (HandleHandshakeServerError (HandshakeProtocolLimit _)) =
192+
classifyHandlerError (HandleHandshakeServerError (HandshakeProtocolLimit _)) =
195193
HandshakeProtocolViolation
196-
classifyHandleError (HandleHandshakeServerError (HandshakeProtocolError _)) =
194+
classifyHandlerError (HandleHandshakeServerError (HandshakeProtocolError _)) =
197195
HandshakeFailure
198196
-- any other exception, e.g. MuxError \/ IOError, codec errors, etc.
199-
classifyHandleError (HandleError _) =
197+
classifyHandlerError (HandlerError _) =
200198
HandshakeProtocolViolation
201199

202200

@@ -208,7 +206,7 @@ type MuxConnectionHandler muxMode socket initiatorCtx responderCtx peerAddr vers
208206
socket
209207
peerAddr
210208
(Handle muxMode initiatorCtx responderCtx versionData bytes m a b)
211-
(HandleError versionNumber)
209+
(HandlerError versionNumber)
212210
versionNumber
213211
versionData
214212
m
@@ -218,15 +216,15 @@ type MuxConnectionHandler muxMode socket initiatorCtx responderCtx peerAddr vers
218216
type MuxConnectionManager muxMode socket initiatorCtx responderCtx peerAddr versionData versionNumber bytes m a b =
219217
ConnectionManager muxMode socket peerAddr
220218
(Handle muxMode initiatorCtx responderCtx versionData bytes m a b)
221-
(HandleError versionNumber)
219+
(HandlerError versionNumber)
222220
m
223221

224222
-- | Type alias for 'ConnectionManager' which is using expanded context.
225223
--
226224
type ConnectionManagerWithExpandedCtx muxMode socket peerAddr versionData versionNumber bytes m a b =
227225
ConnectionManager muxMode socket peerAddr
228226
(HandleWithExpandedCtx muxMode peerAddr versionData bytes m a b)
229-
(HandleError versionNumber)
227+
(HandlerError versionNumber)
230228
m
231229

232230
-- | To be used as `makeConnectionHandler` field of 'ConnectionManagerArguments'.
@@ -311,7 +309,7 @@ makeConnectionHandler muxTracers forkPolicy
311309
socket
312310
peerAddr
313311
(Handle muxMode initiatorCtx responderCtx versionData ByteString m a b)
314-
(HandleError versionNumber)
312+
(HandlerError versionNumber)
315313
versionNumber
316314
versionData
317315
m
@@ -344,7 +342,7 @@ makeConnectionHandler muxTracers forkPolicy
344342
-- handshake negotiation failures, but not with 'IOException's or
345343
-- 'MuxError's.
346344
`catch` \(err :: SomeException) -> do
347-
atomically $ writePromise (Left (HandleError err))
345+
atomically $ writePromise (Left (HandlerError err))
348346
throwIO err
349347
case hsResult of
350348
Left !err -> do
@@ -393,7 +391,7 @@ makeConnectionHandler muxTracers forkPolicy
393391
socket
394392
peerAddr
395393
(Handle muxMode initiatorCtx responderCtx versionData ByteString m a b)
396-
(HandleError versionNumber)
394+
(HandlerError versionNumber)
397395
versionNumber
398396
versionData
399397
m
@@ -426,7 +424,7 @@ makeConnectionHandler muxTracers forkPolicy
426424
-- handshake negotiation failures, but not with 'IOException's or
427425
-- 'MuxError's.
428426
`catch` \(err :: SomeException) -> do
429-
atomically $ writePromise (Left (HandleError err))
427+
atomically $ writePromise (Left (HandlerError err))
430428
throwIO err
431429

432430
case hsResult of

ouroboros-network-framework/src/Ouroboros/Network/ConnectionManager/Core.hs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ data Arguments handlerTrace socket peerAddr handle handleError versionNumber ver
155155
--
156156
connStateIdSupply :: ConnStateIdSupply m,
157157

158-
classifyHandleError :: handleError -> HandleErrorType
158+
classifyHandlerError :: handleError -> HandlerErrorType
159159
}
160160

161161

@@ -404,7 +404,7 @@ with args@Arguments {
404404
connectionsLimits,
405405
updateVersionData,
406406
connStateIdSupply,
407-
classifyHandleError
407+
classifyHandlerError
408408
}
409409
inboundGovernorInfoChannel
410410
ConnectionHandler {
@@ -1079,7 +1079,7 @@ with args@Arguments {
10791079
connState <- readTVar connVar
10801080

10811081
let connState' =
1082-
case classifyHandleError <$> connectionError of
1082+
case classifyHandlerError <$> connectionError of
10831083
ConnectionHandlerError HandshakeFailure ->
10841084
TerminatingState connId connThread
10851085
(case connectionError of
@@ -1815,7 +1815,7 @@ with args@Arguments {
18151815
connState <- readTVar connVar
18161816

18171817
let connState' =
1818-
case classifyHandleError <$> connectionError of
1818+
case classifyHandlerError <$> connectionError of
18191819
ConnectionHandlerError HandshakeFailure ->
18201820
TerminatingState connId connThread
18211821
(case connectionError of

ouroboros-network-framework/src/Ouroboros/Network/ConnectionManager/Types.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ module Ouroboros.Network.ConnectionManager.Types
100100
, ConnectionHandler (..)
101101
, Inactive (..)
102102
, ExceptionInHandler (..)
103-
, HandleErrorType (..)
103+
, HandlerErrorType (..)
104104
, HandshakeConnectionResult (..)
105105
-- ** Prune Policy
106106
, PrunePolicy
@@ -413,7 +413,7 @@ instance Exception ExceptionInHandler
413413

414414
-- | Data type used to classify 'handleErrors'.
415415
--
416-
data HandleErrorType =
416+
data HandlerErrorType =
417417
-- | Handshake negotiation failed. This is not a protocol error.
418418
HandshakeFailure
419419

ouroboros-network-framework/testlib/Test/Ouroboros/Network/ConnectionManager/Experiments.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ withInitiatorOnlyConnectionManager name timeouts trTracer tracer stdGen snocket
326326
connectionsLimits = acceptedConnLimit,
327327
updateVersionData = \a _ -> a,
328328
connStateIdSupply,
329-
classifyHandleError = \_ -> HandshakeFailure
329+
classifyHandlerError = \_ -> HandshakeFailure
330330
}
331331
NotInResponderMode
332332
mkConnectionHandler
@@ -527,7 +527,7 @@ withBidirectionalConnectionManager name timeouts
527527
InitiatorAndResponderDiffusionMode -> Duplex
528528
},
529529
connStateIdSupply,
530-
classifyHandleError = (\_ -> HandshakeFailure)
530+
classifyHandlerError = (\_ -> HandshakeFailure)
531531
}
532532
(InResponderMode inbgovInfoChannel)
533533
connectionHandler

ouroboros-network/src/Ouroboros/Network/Diffusion.hs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -345,10 +345,10 @@ runM Interfaces
345345
:: InformationChannel
346346
(IG.Event 'ResponderMode handle initiatorCtx ntcAddr versionData m c b) m
347347
-> ConnectionHandler 'ResponderMode (ConnectionHandlerTrace ntcVersion ntcVersionData)
348-
ntcFd ntcAddr handle (HandleError versionNumber) version
348+
ntcFd ntcAddr handle (HandlerError versionNumber) version
349349
versionData m
350350
-> ( ConnectionManager 'ResponderMode ntcFd ntcAddr handle
351-
(HandleError versionNumber) m
351+
(HandlerError versionNumber) m
352352
-> m x)
353353
-> m x
354354
localWithConnectionManager responderInfoChannel connectionHandler k =
@@ -370,7 +370,7 @@ runM Interfaces
370370
CM.connectionsLimits = localConnectionLimits,
371371
CM.updateVersionData = \a _ -> a,
372372
CM.connStateIdSupply = diConnStateIdSupply,
373-
CM.classifyHandleError
373+
CM.classifyHandlerError
374374
}
375375
(InResponderMode responderInfoChannel)
376376
connectionHandler
@@ -472,7 +472,7 @@ runM Interfaces
472472
-> StdGen
473473
-> CM.Arguments
474474
(ConnectionHandlerTrace ntnVersion ntnVersionData)
475-
ntnFd ntnAddr handle (HandleError ntnVersion) ntnVersion ntnVersionData m a b
475+
ntnFd ntnAddr handle (HandlerError ntnVersion) ntnVersion ntnVersionData m a b
476476
connectionManagerArguments' prunePolicy stdGen =
477477
CM.Arguments {
478478
CM.tracer = dtConnectionManagerTracer,
@@ -494,7 +494,7 @@ runM Interfaces
494494
CM.outboundIdleTimeout = dcProtocolIdleTimeout,
495495
CM.updateVersionData = daUpdateVersionData,
496496
CM.connStateIdSupply = diConnStateIdSupply,
497-
CM.classifyHandleError
497+
CM.classifyHandlerError
498498
}
499499

500500
let makeConnectionHandler'

ouroboros-network/src/Ouroboros/Network/Diffusion/Types.hs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ module Ouroboros.Network.Diffusion.Types
2121
-- * NodeToClient type aliases
2222
, NodeToClientHandle
2323
, NodeToClientHandleError
24+
, NodeToClientHandlerError
2425
, MkNodeToClientConnectionHandler
2526
-- * NodeToNode type aliases
2627
, NodeToNodeHandle
@@ -610,7 +611,11 @@ type NodeToClientHandle ntcAddr versionData m =
610611
HandleWithMinimalCtx Mx.ResponderMode ntcAddr versionData ByteString m Void ()
611612

612613
type NodeToClientHandleError ntcVersion =
613-
HandleError ntcVersion
614+
HandlerError ntcVersion
615+
{-# DEPRECATED NodeToClientHandleError "Use NodeToClientHandlerError" #-}
616+
617+
type NodeToClientHandlerError ntcVersion =
618+
HandlerError ntcVersion
614619

615620
type MkNodeToClientConnectionHandler
616621
ntcFd ntcAddr ntcVersion ntcVersionData m =
@@ -622,7 +627,7 @@ type MkNodeToClientConnectionHandler
622627
ntcFd
623628
ntcAddr
624629
(NodeToClientHandle ntcAddr ntcVersionData m)
625-
(NodeToClientHandleError ntcVersion)
630+
(NodeToClientHandlerError ntcVersion)
626631
ntcVersion
627632
ntcVersionData
628633
m
@@ -646,7 +651,7 @@ type NodeToNodeConnectionManager
646651
ntnFd
647652
ntnAddr
648653
(NodeToNodeHandle mode ntnAddr ntnVersionData m a b)
649-
(HandleError ntnVersion)
654+
(HandlerError ntnVersion)
650655
m
651656

652657
--

ouroboros-network/src/Ouroboros/Network/PeerSelection/PeerStateActions.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ import Ouroboros.Network.PeerSelection.Governor.Types (PeerStateActions (..))
6666
import Ouroboros.Network.Protocol.Handshake (HandshakeException)
6767
import Ouroboros.Network.RethrowPolicy
6868

69-
import Ouroboros.Network.ConnectionHandler (Handle (..), HandleError (..),
69+
import Ouroboros.Network.ConnectionHandler (Handle (..), HandlerError (..),
7070
MuxConnectionManager)
7171
import Ouroboros.Network.ConnectionManager.Types
7272
import Ouroboros.Network.PeerSelection.PeerSharing (PeerSharing)
@@ -852,7 +852,7 @@ withPeerStateActions PeerStateActionsArguments {
852852
(HandshakeServerFailure err))
853853
throwIO (ServerException err)
854854

855-
HandleError err -> do
855+
HandlerError err -> do
856856
traceWith spsTracer (PeerStatusChangeFailure
857857
(ColdToWarm Nothing remotePeerAddr )
858858
(HandleFailure err))

0 commit comments

Comments
 (0)