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

refactor: wrap rescue inside begin / end block #584

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

theobarrague
Copy link

We are using Puppet 5 ( not a choice, not a choice ... ) and we need the latest version of module with safe_directory.
I had to wrap rescue inside begin / end block to make it works.

@theobarrague theobarrague requested a review from a team as a code owner December 15, 2022 16:02
@bastelfreak
Copy link
Collaborator

@theobarrague can you take a look at the ruvocop violations?

@theobarrague
Copy link
Author

theobarrague commented Dec 26, 2022

Hey @bastelfreak

I'm not sure (I'm not a Ruby developer) but the rescue block seems to work with Ruby 2.5+ only (changelog).
With our Ruby version (2.4.10), it doesn't work without the "implicit" begin block. Without it, the code won't work:

Error: Could not autoload puppet/provider/vcsrepo/git: /opt/puppetlabs/puppet/cache/lib/puppet/provider/vcsrepo/git.rb:294: syntax error, unexpected keyword_rescue, expecting keyword_end
    rescue Puppet::ExecutionFailure
          ^
/opt/puppetlabs/puppet/cache/lib/puppet/provider/vcsrepo/git.rb:731: syntax error, unexpected keyword_end, expecting end-of-input
Error: Could not autoload puppet/type/vcsrepo: Could not autoload puppet/provider/vcsrepo/git: /opt/puppetlabs/puppet/cache/lib/puppet/provider/vcsrepo/git.rb:294: syntax error, unexpected keyword_rescue, expecting keyword_end
    rescue Puppet::ExecutionFailure
          ^
/opt/puppetlabs/puppet/cache/lib/puppet/provider/vcsrepo/git.rb:731: syntax error, unexpected keyword_end, expecting end-of-input
Error: Failed to apply catalog: Could not autoload puppet/type/vcsrepo: Could not autoload puppet/provider/vcsrepo/git: /opt/puppetlabs/puppet/cache/lib/puppet/provider/vcsrepo/git.rb:294: syntax error, unexpected keyword_rescue, expecting keyword_end
    rescue Puppet::ExecutionFailure
          ^
/opt/puppetlabs/puppet/cache/lib/puppet/provider/vcsrepo/git.rb:731: syntax error, unexpected keyword_end, expecting end-of-input

For the SLES-12, it seems failed installing puppet and not related to my PR

@theobarrague
Copy link
Author

Hey @bastelfreak , is there anything wrong with that PR ?

@chelnak
Copy link

chelnak commented Jan 4, 2023

Hey @theobarrague, it looks like there are some rubocop violations still to resolve here.

I'm not entirely sure how much I agree with adding support back in for unsupported Ruby versions.

However, if the community decide this is ok to move forward then we should at least add rule ignores to the relevant lines.

@theobarrague
Copy link
Author

@chelnak it's just a style issue ( Redundant 'begin' block detected https://www.rubydoc.info/gems/rubocop/0.27.0/RuboCop/Cop/Style/RedundantBegin ).
This PR does not change the behavior of the code and make this module compatible with older ruby versions

@LukasAud
Copy link

LukasAud commented Jan 9, 2023

This Rubocop failure seems to be a blocker for our unit tests. Obviously this is not ideal as we need our tests to be running properly if we want to be able monitor our modules. Either we add an exception to make Rubocop ignore the 'begin' lines (not ideal, we are already working on removing exceptions and outdated syntax) or we find an alternative.

What do you think, @chelnak?

@theobarrague
Copy link
Author

theobarrague commented Jan 17, 2023

@chelnak up 🙂

In my opinion, if you started to migrate old syntax to new syntax, close this PR.

Otherwise, if it's acceptable for you to have a few old syntax ( which don't change the behavior ) to support more versions of Puppet, merge ( i can add the rubocop rules ).

But in any case, please take a decision so i can continue with / without.

@CLAassistant
Copy link

CLAassistant commented Apr 19, 2023

CLA assistant check
All committers have signed the CLA.

@LukasAud
Copy link

Hey @theobarrague, sorry for the long delay in replying. I'm looking again at this and the Pull Request needs a rebase. If you can add the "redundant begin" rule exception to the rubocop_todo.yml (file introduced in our Puppet 8 update) alongside a small comment as to why it exists, I think we would be happy to merge this.

Also, I know sometimes its not possible but if you are still using Puppet 5, I would recommend updating to newer, supported versions 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants