Skip to content

Mention qualified property name in Get or Set errors #147

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

Merged
merged 10 commits into from
Apr 3, 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
7 changes: 6 additions & 1 deletion .github/workflows/ruby.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,17 @@ jobs:
bundler-cache: true # runs 'bundle install' and caches installed gems automatically

- name: Run tests
run: bundle exec rake
run: bundle exec rake spec
# enable code coverage reporting
env:
COVERAGE: 'true'
COVERAGE_LCOV: 'true'

- name: Run RuboCop
# only for latest version, it is dropping Ruby support fster than us
if: ${{ matrix.ruby-version == '3.4' }}
run: bundle exec rake rubocop

- name: Coveralls Report
# send it only for the latest version to avoid duplicate submits
if: ${{ matrix.ruby-version == '3.4' }}
Expand Down
9 changes: 9 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
inherit_from: .rubocop_todo.yml

AllCops:
TargetRubyVersion: 2.4
SuggestExtensions: false
NewCops: enable
Exclude:
# Do not check code borrowed from ActiveSupport
- 'lib/dbus/core_ext/**/*.rb'
Expand Down Expand Up @@ -73,6 +77,11 @@ Lint/RescueException:
Naming/PredicateName:
NamePrefix:
# has_ and have_ are allowed
- does_
- is_
ForbiddenPrefixes:
# has_ and have_ are allowed
- does_
- is_

# Offense count: 1
Expand Down
151 changes: 151 additions & 0 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2025-04-03 13:59:12 UTC using RuboCop version 1.68.0.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
# versions of RuboCop, may require this file to be generated again.

# Offense count: 2
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: Include.
# Include: **/*.gemspec
Gemspec/AddRuntimeDependency:
Exclude:
- 'ruby-dbus.gemspec'

# Offense count: 8
# Configuration parameters: EnforcedStyle, AllowedGems, Include.
# SupportedStyles: Gemfile, gems.rb, gemspec
# Include: **/*.gemspec, **/Gemfile, **/gems.rb
Gemspec/DevelopmentDependencies:
Exclude:
- 'ruby-dbus.gemspec'

# Offense count: 1
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: Severity, Include.
# Include: **/*.gemspec
Gemspec/RequireMFA:
Exclude:
- 'ruby-dbus.gemspec'

# Offense count: 3
# Configuration parameters: AllowComments, AllowEmptyLambdas.
Lint/EmptyBlock:
Exclude:
- 'examples/utils/notify.rb'
- 'spec/object_spec.rb'
- 'spec/signal_spec.rb'

# Offense count: 1
# This cop supports unsafe autocorrection (--autocorrect-all).
Lint/IncompatibleIoSelectWithFiberScheduler:
Exclude:
- 'lib/dbus/message_queue.rb'

# Offense count: 3
# This cop supports unsafe autocorrection (--autocorrect-all).
Style/EnvHome:
Exclude:
- 'examples/no-introspect/tracker-test.rb'
- 'lib/dbus/auth.rb'
- 'lib/dbus/bus.rb'

# Offense count: 10
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: AllowedVars.
Style/FetchEnvVar:
Exclude:
- 'examples/no-introspect/tracker-test.rb'
- 'lib/dbus/auth.rb'
- 'lib/dbus/bus.rb'
- 'lib/dbus/logger.rb'
- 'spec/connection_spec.rb'
- 'spec/coverage_helper.rb'
- 'spec/session_bus_spec.rb'
- 'spec/spec_helper.rb'

# Offense count: 1
# This cop supports unsafe autocorrection (--autocorrect-all).
# Configuration parameters: AllowSplatArgument.
Style/HashConversion:
Exclude:
- 'lib/dbus/data.rb'

# Offense count: 1
# This cop supports unsafe autocorrection (--autocorrect-all).
Style/MapIntoArray:
Exclude:
- 'lib/dbus/marshall.rb'

# Offense count: 1
# This cop supports unsafe autocorrection (--autocorrect-all).
Style/MinMaxComparison:
Exclude:
- 'lib/dbus/auth.rb'

# Offense count: 2
# This cop supports safe autocorrection (--autocorrect).
Style/NegatedIfElseCondition:
Exclude:
- 'lib/dbus/connection.rb'

# Offense count: 3
Style/OpenStructUse:
Exclude:
- 'spec/packet_marshaller_spec.rb'
- 'spec/packet_unmarshaller_spec.rb'
- 'spec/property_spec.rb'

# Offense count: 5
# This cop supports unsafe autocorrection (--autocorrect-all).
# Configuration parameters: Methods.
Style/RedundantArgument:
Exclude:
- 'lib/dbus/auth.rb'
- 'lib/dbus/introspect.rb'
- 'lib/dbus/object.rb'

# Offense count: 4
# This cop supports safe autocorrection (--autocorrect).
Style/RedundantConstantBase:
Exclude:
- 'spec/data_spec.rb'

# Offense count: 1
# This cop supports unsafe autocorrection (--autocorrect-all).
Style/RedundantEach:
Exclude:
- 'spec/type_spec.rb'

# Offense count: 3
# This cop supports safe autocorrection (--autocorrect).
Style/RedundantRegexpArgument:
Exclude:
- 'examples/service/service_newapi.rb'
- 'lib/dbus/object.rb'
- 'spec/mock-service/spaghetti-monster.rb'

# Offense count: 2
# This cop supports unsafe autocorrection (--autocorrect-all).
Style/StringChars:
Exclude:
- 'examples/service/service_newapi.rb'
- 'spec/mock-service/spaghetti-monster.rb'

# Offense count: 6
# This cop supports safe autocorrection (--autocorrect).
Style/SuperArguments:
Exclude:
- 'examples/service/complex-property.rb'
- 'lib/dbus/data.rb'
- 'lib/dbus/introspect.rb'
- 'spec/mock-service/spaghetti-monster.rb'

# Offense count: 2
# This cop supports safe autocorrection (--autocorrect).
Style/SuperWithArgsParentheses:
Exclude:
- 'lib/dbus/object.rb'
- 'spec/mock-service/spaghetti-monster.rb'
4 changes: 4 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
source "https://rubygems.org"
gemspec

gem "rubocop", "~> 1.68.0" if RUBY_VERSION >= "2.7"
# newer versions have a noise deprecation warning
gem "rubocop-ast", "~> 1.36.0" if RUBY_VERSION >= "2.7"

group :test do
# Optional dependency, we do want to test with it
gem "nokogiri"
Expand Down
8 changes: 8 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@

## Unreleased

## Ruby D-Bus 0.25.0 - 2025-04-03

Bug fixes:
* Mention qualified property name in Get or Set errors ([#147][]).
* Fix declaring logger and ostruct gems for Ruby 3.5

[#147]: https://github.com/mvidner/ruby-dbus/pull/147

## Ruby D-Bus 0.24.0 - 2025-01-02

Bug fixes:
Expand Down
13 changes: 9 additions & 4 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
require "rake"
require "fileutils"
require "tmpdir"
require "rspec/core/rake_task"
require "shellwords"
begin
require "rubocop/rake_task"
rescue LoadError
Expand Down Expand Up @@ -34,13 +34,18 @@ desc "Default: run specs in the proper environment"
task default: [:spec, :rubocop]
task test: :spec

RSpec::Core::RakeTask.new("bare:spec")
desc "Run RSpec code examples"
task "bare:spec", [:options] do |_t, args|
args.with_defaults(options: "")
sh "rspec #{args[:options]}"
end

["spec"].each do |tname|
desc "Run bare:#{tname} in the proper environment"
task tname do |_t|
task tname, [:options] do |_t, args|
args.with_defaults(options: "")
cd "spec/tools" do
sh "./test_env rake bare:#{tname}"
sh "./test_env rake bare:#{tname}[#{args[:options].shellescape}]"
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.24.0
0.25.0
2 changes: 1 addition & 1 deletion lib/dbus/logger.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ module DBus
# The default one logs to STDERR,
# with DEBUG if $DEBUG is set, otherwise INFO.
def logger
if @logger.nil?
if !defined?(@logger) || @logger.nil?
debug = $DEBUG || ENV["RUBY_DBUS_DEBUG"]
@logger = Logger.new($stderr)
@logger.level = debug ? Logger::DEBUG : Logger::INFO
Expand Down
2 changes: 1 addition & 1 deletion lib/dbus/marshall.rb
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ def num_align(num, alignment)
case alignment
when 1, 2, 4, 8
bits = alignment - 1
num + bits & ~bits
(num + bits) & ~bits
else
raise ArgumentError, "Unsupported alignment #{alignment}"
end
Expand Down
6 changes: 3 additions & 3 deletions lib/dbus/message.rb
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,9 @@ def initialize(mtype = INVALID)

def to_s
"#{message_type} sender=#{sender} -> dest=#{destination} " \
"serial=#{serial} reply_serial=#{reply_serial} " \
"path=#{path}; interface=#{interface}; member=#{member} " \
"error_name=#{error_name}"
"serial=#{serial} reply_serial=#{reply_serial} " \
"path=#{path}; interface=#{interface}; member=#{member} " \
"error_name=#{error_name}"
end

# @return [String] name of message type, as used in match rules:
Expand Down
40 changes: 25 additions & 15 deletions lib/dbus/object.rb
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ def self.dbus_interface(name)

# Forgetting to declare the interface for a method/signal/property
# is a ScriptError.
class UndefinedInterface < ScriptError # rubocop:disable Lint/InheritException
class UndefinedInterface < ScriptError
def initialize(sym)
super "No interface specified for #{sym}. Enclose it in dbus_interface."
end
Expand Down Expand Up @@ -253,7 +253,7 @@ def self.dbus_reader(ruby_name, type, dbus_name: nil, emits_changed_signal: nil)
property = Property.new(dbus_name, type, :read, ruby_name: ruby_name)
@@cur_intf.define(property)

ruby_name_eq = "#{ruby_name}=".to_sym
ruby_name_eq = :"#{ruby_name}="
return unless method_defined?(ruby_name_eq)

dbus_watcher(ruby_name, dbus_name: dbus_name, emits_changed_signal: emits_changed_signal)
Expand Down Expand Up @@ -294,7 +294,7 @@ def self.dbus_watcher(ruby_name, dbus_name: nil, emits_changed_signal: nil)
interface_name = @@cur_intf.name

ruby_name = ruby_name.to_s.sub(/=$/, "").to_sym
ruby_name_eq = "#{ruby_name}=".to_sym
ruby_name_eq = :"#{ruby_name}="
original_ruby_name_eq = "_original_#{ruby_name_eq}"

dbus_name = make_dbus_name(ruby_name, dbus_name: dbus_name)
Expand Down Expand Up @@ -455,11 +455,16 @@ def interfaces_and_properties
property = dbus_lookup_property(interface_name, property_name)

if property.readable?
ruby_name = property.ruby_name
value = public_send(ruby_name)
# may raise, DBus.error or https://ruby-doc.com/core-3.1.0/TypeError.html
typed_value = Data.make_typed(property.type, value)
[typed_value]
begin
ruby_name = property.ruby_name
value = public_send(ruby_name)
# may raise, DBus.error or https://ruby-doc.com/core-3.1.0/TypeError.html
typed_value = Data.make_typed(property.type, value)
[typed_value]
rescue StandardError => e
msg = "When getting '#{interface_name}.#{property_name}': " + e.message
raise e.exception(msg)
end
else
raise DBus.error("org.freedesktop.DBus.Error.PropertyWriteOnly"),
"Property '#{interface_name}.#{property_name}' (on object '#{@path}') is not readable"
Expand All @@ -470,11 +475,16 @@ def interfaces_and_properties
property = dbus_lookup_property(interface_name, property_name)

if property.writable?
ruby_name_eq = "#{property.ruby_name}="
# TODO: declare dbus_method :Set to take :exact argument
# and type check it here before passing its :plain value
# to the implementation
public_send(ruby_name_eq, value)
begin
ruby_name_eq = "#{property.ruby_name}="
# TODO: declare dbus_method :Set to take :exact argument
# and type check it here before passing its :plain value
# to the implementation
public_send(ruby_name_eq, value)
rescue StandardError => e
msg = "When setting '#{interface_name}.#{property_name}': " + e.message
raise e.exception(msg)
end
else
raise DBus.error("org.freedesktop.DBus.Error.PropertyReadOnly"),
"Property '#{interface_name}.#{property_name}' (on object '#{@path}') is not writable"
Expand Down Expand Up @@ -507,8 +517,8 @@ def interfaces_and_properties
typed_value = Data.make_typed(property.type, value)
p_hash[p_name.to_s] = typed_value
rescue StandardError
DBus.logger.debug "Property '#{interface_name}.#{p_name}' (on object '#{@path}')" \
" has raised during GetAll, omitting it"
DBus.logger.debug "Property '#{interface_name}.#{p_name}' (on object '#{@path}') " \
"has raised during GetAll, omitting it"
end
end

Expand Down
Loading