Skip to content

Commit

Permalink
Capture WebChannels exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
essenciary committed Oct 19, 2023
1 parent 715de66 commit 86e1aec
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 19 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "Genie"
uuid = "c43c736e-a2d1-11e8-161f-af95117fbd1e"
authors = ["Adrian Salceanu <[email protected]>"]
version = "5.19.0"
version = "5.19.1"

[deps]
ArgParse = "c7e460c6-2fb9-53a9-8c5b-16f535851c63"
Expand Down
45 changes: 27 additions & 18 deletions src/WebChannels.jl
Original file line number Diff line number Diff line change
Expand Up @@ -221,25 +221,29 @@ function broadcast(channels::Union{ChannelName,Vector{ChannelName}},

isempty(SUBSCRIPTIONS) && return false

for channel in channels
haskey(SUBSCRIPTIONS, channel) || throw(ChannelNotFoundException(channel))

for client in SUBSCRIPTIONS[channel]
except !== nothing && client == id(except) && continue
HTTP.WebSockets.isclosed(CLIENTS[client].client) && continue

try
payload !== nothing ?
message(client, ChannelMessage(channel, client, msg, payload) |> Renderer.Json.JSONParser.json) :
message(client, msg)
catch ex
if isa(ex, Base.IOError)
unsubscribe_disconnected_clients(channel)
else
@error ex
try
for channel in channels
haskey(SUBSCRIPTIONS, channel) || throw(ChannelNotFoundException(channel))

for client in SUBSCRIPTIONS[channel]
except !== nothing && client == id(except) && continue
HTTP.WebSockets.isclosed(CLIENTS[client].client) && continue

try
payload !== nothing ?
message(client, ChannelMessage(channel, client, msg, payload) |> Renderer.Json.JSONParser.json) :
message(client, msg)
catch ex
if isa(ex, Base.IOError)
unsubscribe_disconnected_clients(channel)
else
@error ex
end
end
end
end
catch ex
@error ex
end

true
Expand All @@ -253,8 +257,13 @@ function broadcast(msg::String;
channels::Union{Union{ChannelName,Vector{ChannelName}},Nothing} = nothing,
payload::Union{Dict,Nothing} = nothing,
except::Union{HTTP.WebSockets.WebSocket,Nothing,UInt} = nothing) :: Bool
channels === nothing && (channels = collect(keys(SUBSCRIPTIONS)))
broadcast(channels, msg, payload; except = except)
try
channels === nothing && (channels = collect(keys(SUBSCRIPTIONS)))
broadcast(channels, msg, payload; except = except)
catch ex
@error ex
false
end
end


Expand Down

2 comments on commit 86e1aec

@essenciary
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/93704

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v5.19.1 -m "<description of version>" 86e1aec8f50322e0d3ee07e64bc611914628914c
git push origin v5.19.1

Please sign in to comment.