Error Handling
Websockets are inherently asynchronous, so error handling can be inflexible.
SimpleWebsockets.jl offers the user event hooks to register callbacks and handle errors flexibly.
SEE: Server Events, Client Events, Connection Events
If no callbacks are registered, hardcoded @info
, @warn
and @error
calls will provide logging feedback, but the parent process will remain unaffected by exceptions unless as below.
Errors in user provided callback error handlers will log the error and exit
the process.
Unregistered callbacks for the following situations will log the error and exit
the process:
- A error occured in a user provided callback function
- The client/server could not initialise on the network
WebsocketError
SimpleWebsockets.WebsocketError
— Typeabstract type WebsocketError <: Exception
WebsocketError child error types have the following fields:
- msg::String
- log::Function
The log()
function will internally call: @error msg exception = (err, trace)
Where trace
is the backtrace of the exception origin.
WebsocketError types
SimpleWebsockets.ConnectError
— Typestruct ConnectError <: WebsocketError
An exception originated while trying to start a server or connect a client to a server
SimpleWebsockets.PeerConnectError
— Typestruct PeerConnectError <: WebsocketError
The server made an exception when a client tried to connect
SimpleWebsockets.CallbackError
— Typestruct CallbackError <: WebsocketError
An exception originated in a user provided callback function
SimpleWebsockets.FrameError
— Typestruct FrameError <: WebsocketError
An exception originated while parsing a websocket data frame