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>
This commit is contained in:
Wesley Schwengle 2024-04-09 02:28:40 -04:00 committed by GitHub
parent 47cab33aa8
commit d91597b1c1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -315,6 +315,11 @@ sub subscribe {
# Register callbacks for each message type # Register callbacks for each message type
for my $key (keys %{$callbacks}) { 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}; my $type = $events{$key};
$self->{callbacks}->{$type} = $callbacks->{$key}; $self->{callbacks}->{$type} = $callbacks->{$key};
} }