diff options
author | Wesley Schwengle <wesleys@opperschaap.net> | 2024-04-09 02:28:40 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-04-09 08:28:40 +0200 |
commit | d91597b1c1a51c41a1fc65c3ad8760b786522d83 (patch) | |
tree | e23156b7005ae113b949c48176bb2f171ec25256 | |
parent | 47cab33aa8b3c8b47e34de6148440a1bc30a2297 (diff) | |
download | i3-d91597b1c1a51c41a1fc65c3ad8760b786522d83.tar.gz i3-d91597b1c1a51c41a1fc65c3ad8760b786522d83.zip |
Check if subscribe event type is supported in AnyEvent::I3 (#5988)
Add simple `if exists' construct in the subscribe function. This
prevents a somewhat cryptic warnings such as these:
Use of uninitialized value $type in hash element at
/usr/share/perl5/AnyEvent/I3.pm line 309.
We still warn the user, but it is much clearer as to what the cause is.
It now shows something like this:
Could not subscribe to event type 'foo'. Supported events are _error
barconfig_update binding mode output shutdown tick window workspace
Signed-off-by: Wesley Schwengle <wesleys@opperschaap.net>
-rw-r--r-- | AnyEvent-I3/lib/AnyEvent/I3.pm | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/AnyEvent-I3/lib/AnyEvent/I3.pm b/AnyEvent-I3/lib/AnyEvent/I3.pm index 1f4e5bd3..0a272300 100644 --- a/AnyEvent-I3/lib/AnyEvent/I3.pm +++ b/AnyEvent-I3/lib/AnyEvent/I3.pm @@ -315,6 +315,11 @@ sub subscribe { # Register callbacks for each message type for my $key (keys %{$callbacks}) { + if (!exists $events{$key}) { + warn "Could not subscribe to event type '$key'." . + " Supported events are " . join(" ", sort keys %events), $/; + next; + } my $type = $events{$key}; $self->{callbacks}->{$type} = $callbacks->{$key}; } |