From d91597b1c1a51c41a1fc65c3ad8760b786522d83 Mon Sep 17 00:00:00 2001 From: Wesley Schwengle Date: Tue, 9 Apr 2024 02:28:40 -0400 Subject: 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 --- AnyEvent-I3/lib/AnyEvent/I3.pm | 5 +++++ 1 file changed, 5 insertions(+) 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}; } -- cgit v1.2.3-54-g00ecf