Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support ruby 3.4 backtrace formatting change #145

Merged
merged 1 commit into from
Jan 2, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions lib/dbus/proxy_object.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ class ProxyObject
# @return [ApiOptions]
attr_reader :api

OPEN_QUOTE = RUBY_VERSION >= "3.4" ? "'" : "`"

# Creates a new proxy object living on the given _bus_ at destination _dest_
# on the given _path_.
def initialize(bus, dest, path, api: ApiOptions::CURRENT)
Expand All @@ -58,7 +60,7 @@ def interfaces
def [](intfname)
introspect unless introspected
ifc = @interfaces[intfname]
raise DBus::Error, "no such interface `#{intfname}' on object `#{@path}'" unless ifc
raise DBus::Error, "no such interface #{OPEN_QUOTE}#{intfname}' on object #{OPEN_QUOTE}#{@path}'" unless ifc

ifc
end
Expand Down Expand Up @@ -127,7 +129,8 @@ def has_iface?(name)
# @return [void]
def on_signal(name, &block)
unless @default_iface && has_iface?(@default_iface)
raise NoMethodError, "undefined signal `#{name}' for DBus interface `#{@default_iface}' on object `#{@path}'"
raise NoMethodError, "undefined signal #{OPEN_QUOTE}#{name}' for DBus interface "\
"#{OPEN_QUOTE}#{@default_iface}' on object #{OPEN_QUOTE}#{@path}'"
end

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

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

# BTW e.exception("...") would preserve the class.
raise NoMethodError, "undefined method `#{name}' for DBus interface `#{@default_iface}' on object `#{@path}'"
raise NoMethodError, "undefined method #{OPEN_QUOTE}#{name}' for DBus interface "\
"#{OPEN_QUOTE}#{@default_iface}' on object #{OPEN_QUOTE}#{@path}'"
end
end
# rubocop:enable Lint/MissingSuper
Expand Down
3 changes: 2 additions & 1 deletion spec/signal_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,10 @@ def new_quitter(main_loop)
describe DBus::ProxyObject do
describe "#on_signal" do
it "raises a descriptive error when the default_iface is wrong" do
open_quote = RUBY_VERSION >= "3.4" ? "'" : "`"
@obj.default_iface = "org.ruby.NoSuchInterface"
expect { @obj.on_signal("Foo") {} }
.to raise_error(NoMethodError, /undefined signal.*interface `org.ruby.NoSuchInterface'/)
.to raise_error(NoMethodError, /undefined signal.*interface #{open_quote}org.ruby.NoSuchInterface'/)
end
end
end
Expand Down
Loading