Skip to content

Commit 225c641

Browse files
committed
Handle nil @syslog in syslog sink add_record
After resetting @syslog to nil between tests, some tests that use the syslog sink without calling open() first would fail with: "undefined method `log' for nil" Add a guard clause to return early if @syslog is nil, preventing errors when the sink hasn't been properly opened yet. This is a defensive check that allows the sink to gracefully handle uninitialized state.
1 parent d434260 commit 225c641

File tree

2 files changed

+2
-3
lines changed

2 files changed

+2
-3
lines changed

lib/steno/sink/syslog.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ def open(identity)
3535

3636
def add_record(record)
3737
return if record.log_level == :off
38+
return unless @syslog
3839

3940
record = truncate_record(record)
4041
msg = @codec.encode_record(record)

spec/spec_helper.rb

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -207,9 +207,7 @@
207207

208208
rspec_config.after do
209209
# Reset the Syslog sink singleton to prevent mock leakage between tests
210-
if defined?(Steno::Sink::Syslog)
211-
Steno::Sink::Syslog.instance.instance_variable_set(:@syslog, nil)
212-
end
210+
Steno::Sink::Syslog.instance.instance_variable_set(:@syslog, nil) if defined?(Steno::Sink::Syslog)
213211
end
214212

215213
rspec_config.after(:each, type: :legacy_api) { add_deprecation_warning }

0 commit comments

Comments
 (0)