Skip to content

Commit 3e8e33e

Browse files
authored
Merge pull request #145 from mtasaka/ruby34-fix
Support ruby 3.4 backtrace formatting change https://bugs.ruby-lang.org/issues/16495 "Inconsistent quotes in error messages" https://www.ruby-lang.org/en/news/2024/12/12/ruby-3-4-0-rc1-released/
2 parents 5f98ee3 + 1ef9458 commit 3e8e33e

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

lib/dbus/proxy_object.rb

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ class ProxyObject
3333
# @return [ApiOptions]
3434
attr_reader :api
3535

36+
OPEN_QUOTE = RUBY_VERSION >= "3.4" ? "'" : "`"
37+
3638
# Creates a new proxy object living on the given _bus_ at destination _dest_
3739
# on the given _path_.
3840
def initialize(bus, dest, path, api: ApiOptions::CURRENT)
@@ -58,7 +60,7 @@ def interfaces
5860
def [](intfname)
5961
introspect unless introspected
6062
ifc = @interfaces[intfname]
61-
raise DBus::Error, "no such interface `#{intfname}' on object `#{@path}'" unless ifc
63+
raise DBus::Error, "no such interface #{OPEN_QUOTE}#{intfname}' on object #{OPEN_QUOTE}#{@path}'" unless ifc
6264

6365
ifc
6466
end
@@ -127,7 +129,8 @@ def has_iface?(name)
127129
# @return [void]
128130
def on_signal(name, &block)
129131
unless @default_iface && has_iface?(@default_iface)
130-
raise NoMethodError, "undefined signal `#{name}' for DBus interface `#{@default_iface}' on object `#{@path}'"
132+
raise NoMethodError, "undefined signal #{OPEN_QUOTE}#{name}' for DBus interface "\
133+
"#{OPEN_QUOTE}#{@default_iface}' on object #{OPEN_QUOTE}#{@path}'"
131134
end
132135

133136
@interfaces[@default_iface].on_signal(name, &block)
@@ -151,18 +154,20 @@ def method_missing(name, *args, &reply_handler)
151154
# - di not specified
152155
# TODO
153156
# - di is specified but not found in introspection data
154-
raise NoMethodError, "undefined method `#{name}' for DBus interface `#{@default_iface}' on object `#{@path}'"
157+
raise NoMethodError, "undefined method #{OPEN_QUOTE}#{name}' for DBus interface "\
158+
"#{OPEN_QUOTE}#{@default_iface}' on object #{OPEN_QUOTE}#{@path}'"
155159
end
156160

157161
begin
158162
@interfaces[@default_iface].method(name).call(*args, &reply_handler)
159163
rescue NameError => e
160164
# interesting, foo.method("unknown")
161165
# raises NameError, not NoMethodError
162-
raise unless e.to_s =~ /undefined method `#{name}'/
166+
raise unless e.to_s =~ /undefined method #{OPEN_QUOTE}#{name}'/
163167

164168
# BTW e.exception("...") would preserve the class.
165-
raise NoMethodError, "undefined method `#{name}' for DBus interface `#{@default_iface}' on object `#{@path}'"
169+
raise NoMethodError, "undefined method #{OPEN_QUOTE}#{name}' for DBus interface "\
170+
"#{OPEN_QUOTE}#{@default_iface}' on object #{OPEN_QUOTE}#{@path}'"
166171
end
167172
end
168173
# rubocop:enable Lint/MissingSuper

spec/signal_spec.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,10 @@ def new_quitter(main_loop)
107107
describe DBus::ProxyObject do
108108
describe "#on_signal" do
109109
it "raises a descriptive error when the default_iface is wrong" do
110+
open_quote = RUBY_VERSION >= "3.4" ? "'" : "`"
110111
@obj.default_iface = "org.ruby.NoSuchInterface"
111112
expect { @obj.on_signal("Foo") {} }
112-
.to raise_error(NoMethodError, /undefined signal.*interface `org.ruby.NoSuchInterface'/)
113+
.to raise_error(NoMethodError, /undefined signal.*interface #{open_quote}org.ruby.NoSuchInterface'/)
113114
end
114115
end
115116
end

0 commit comments

Comments
 (0)