Skip to content

(PUP-11974) Only warn when Ruby's verbose is enabled #9129

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 3 commits into from
Oct 18, 2023

Conversation

joshcooper
Copy link
Contributor

In ruby 2.7.x, the rb_file_exists_p and rb_dir_exists_p methods call rb_warning to log that the methods are deprecated[1][2] However, the rb_warning method is a noop if $VERBOSE is nil or false[3] To preserve the same behavior, only warn when $VERBOSE is truthy. Also include the class name and path in the warning so we can identify and fix the issue.

[1] https://github.com/ruby/ruby/blob/1f4d4558484b370999954f3ede7e3aa3a3a01ef3/file.c#L1819
[2] https://github.com/ruby/ruby/blob/1f4d4558484b370999954f3ede7e3aa3a3a01ef3/dir.c#L3301
[3] https://github.com/ruby/ruby/blob/1f4d4558484b370999954f3ede7e3aa3a3a01ef3/error.c#L336-L338

@joshcooper joshcooper requested a review from a team as a code owner October 17, 2023 19:09
@joshcooper joshcooper marked this pull request as draft October 17, 2023 19:29
In ruby 2.7.x, the rb_file_exists_p and rb_dir_exists_p methods call
rb_warning to log that the methods are deprecated[1][2] However, the
rb_warning method is a noop if $VERBOSE is nil or false[3] To preserve
the same behavior, only warn when $VERBOSE is truthy. Also include the
class name and path in the warning so we can identify and fix the issue.

[1] https://github.com/ruby/ruby/blob/1f4d4558484b370999954f3ede7e3aa3a3a01ef3/file.c#L1819
[2] https://github.com/ruby/ruby/blob/1f4d4558484b370999954f3ede7e3aa3a3a01ef3/dir.c#L3301
[3] https://github.com/ruby/ruby/blob/1f4d4558484b370999954f3ede7e3aa3a3a01ef3/error.c#L336-L338
Previously we were disabling $VERBOSE so that we could stub a constant during
tests without generating warnings like:

    warning: already initialized constant ...

Just use `stub_const`, which doesn't cause those warnings and it automatically
restores the original value when the block completes.
If the block passed to `with_verbose_disabled` raised, then $VERBOSE wasn't
restored to its original value. This method isn't used in puppet, but has been
here a long time, so guard against the issue instead of removing the method.
@joshcooper joshcooper marked this pull request as ready for review October 18, 2023 05:32
@joshcooper joshcooper merged commit eb2c7d2 into puppetlabs:main Oct 18, 2023
@joshcooper joshcooper deleted the ruby_warning branch October 18, 2023 05:32
@joshcooper joshcooper added the bug Something isn't working label Nov 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants