Why could `rb_sysopen` not be found anymore by the custom fact since the upgrade to Puppet4? - ruby

The following custom fact:
# returns latest packerversion, e.g. 0.10.1
Facter.add("latest_packerversion") do
setcode do
url="https://www.packer.io/downloads.html"
file = open("#{url}")
contents = file.read()
match = contents.match(/Latest\sversion:\s(.*)</)
match[1]
end
end
worked using puppet 3.6.2, but since the upgrade to 4.5.2 the following issue occurs:
Error: Facter: error while resolving custom fact "latest_packerversion":
No such file or directory # rb_sysopen - https://www.packer.io/downloads.html
Analysis
It seems that the rb_sysopen could not be found anymore for some reason (No such file or directory # rb_sysopen) since the upgrade to Puppet 4.
Puppet4 seems to use an embedded ruby version instead of the one installed on the host (Puppet3):
Puppet 4, both Facter 2.4 and CFacter 0.4, the latest Hiera and
Mcollective, as well Ruby 2.1.5, OpenSSL 1.0.0r, and our gem
dependencies.
Does rb_sysopen not exist in Ruby 2.1.5? No evidence was found.
Perhaps a change related to facts have occurred that could cause the issue? Nothing related was found in the release notes.
Question
Why could rb_sysopen not be found anymore by the custom fact since the upgrade to Puppet4?

Concise
I will include require 'open-uri' in both facts, but I do not understand why this is required since the upgrade to Puppet4
Verbose
Once require 'open-uri' is included in one of the custom facts the issue is solved.
# returns latest gitversion, e.g. 2.8.2
Facter.add("latest_gitversion") do
setcode do
require 'open-uri'
url="https://git-scm.com/downloads"
file = open("#{url}")
contents = file.read()
match = contents.match(/RelNotes.*((\d\.){2}\d)/)
match[1]
end
end
As soon as the require 'open-uri' has been commented out, the issue occurs again:
Error: Facter: error while resolving custom fact "latest_gitversion": No such file or directory # rb_sysopen - https://git-scm.com/downloads
Error: Facter: error while resolving custom fact "latest_packerversion": No such file or directory # rb_sysopen - https://www.packer.io/downloads.html
At the moment it is unclear what is causing the issue.

Related

unexpected keyword_rescue, expecting keyword_end (SyntaxError) [duplicate]

I have the following ruby code:
EmailTemplate.for(mailer).each do |template|
begin
print '.'
template.upload(publish)
rescue Mandrill::UnknownTemplateError
failed.push(mailer)
end
end
Rubocop corrected my code to:
EmailTemplate.for(mailer).each do |template|
print '.'
template.upload(publish)
rescue Mandrill::UnknownTemplateError
failed.push(mailer)
end
and now it returns following error:
syntax error, unexpected keyword_rescue, expecting keyword_end
How can I fix that?
Rubocop warnings was:
C: Style/RedundantBegin: Redundant begin block detected.
Ruby 2.5.0 added a feature:
rescue/else/ensure are now allowed to be used directly with do/end blocks. [Feature #12906]
But before that, it was not allowed. So syntax error will be there.
Lets do syntax test for the code in sample.rb:
[].each do |a|
# ops
rescue Exception => ex
puts ex.inspect
end
From terminal:
Ruby$ ruby -c sample.rb
sample.rb:3: syntax error, unexpected keyword_rescue
rescue Exception => ex
^
sample.rb:5: syntax error, unexpected keyword_end, expecting end-of-input
Ruby$ rvm use 2.5.1
Using /Users/aruprakshit/.rvm/gems/ruby-2.5.1
Ruby$ ruby -c sample.rb
Syntax OK
See the News. So before 2.5.0, you need to write it like:
[].each do |a|
begin
# ops
rescue => Exception
puts ex.inspect
end
end
You can configure Rubocop to select the version of Ruby you want by following Setting the target Ruby version.
Some checks are dependent on the version of the Ruby interpreter which
the inspected code must run on. For example, enforcing using Ruby 2.3+
safe navigation operator rather than try can help make your code
shorter and more consistent... unless it must run on Ruby 2.2.
If .ruby-version exists in the directory RuboCop is invoked in,
RuboCop will use the version specified by it. Otherwise, users may let
RuboCop know the oldest version of Ruby which your project supports
with:
AllCops:
TargetRubyVersion: 2.4
For some reason, Rubocop thinks you're running Ruby 2.5, not Ruby 2.4.1.
You can fix this one of two ways:
1) Create a file .ruby-version with content 2.4.1. Rubocop should pick up your Ruby version from this file.
2) Add the following to your .rubocop.yml:
AllCops:
TargetRubyVersion: 2.4

Ocra error "No such file or directory # rb_sysopen" in Ocra when compiling

"No such file or directory # rb_sysopen - C:/Users//OneDrive/Desktop/ruby/fiber.so (Errno::ENOENT)" keeps getting thrown by Ocra when I try to compile my app into an exe.
I've used fixes mentioned by others but none of them work, likely because most of them are for an older version of Ruby.
I'm using Ruby2d and I include it in my command:
ocra --verbose move.rb --no-dep-run --gem-minimal=ruby2d

rqrcode on ruby rails

I tried the example in this website:
https://richonrails.com/articles/generating-qr-codes-in-your-ruby-on-rails-application
to generate a qr code. there seems to be a problem with the require 'rqrcode' line which I have in the config/environment.rb file.
I checked that the gem is installed and it is. I removed the line require 'rqrcode' from the config/environment.rb file and then I get error 'uninitialized constant QrCodesController::RQRCode' at the controller:
def create
#qr = RQRCode::QRCode.new(qr_code_params[:text],size:4)
end
when I re-add the line require 'rqrcode' and restart the rails server, I get the error - 'require': cannot load such file - rqrcode (LoadError).
Thanks in advance for the help!

On Windows paperclip uses "file" command in Ruby Devkit, but gives error "Errno::EEXIST in ArticlesController#create"

On Ubuntu paperclip file upload works with builtin file command. On Windows I did both install Ruby Devkit or file.exe in PATH variable: None of this helps! I get:
File exists # sys_fail2 - C:/Users/Lap127/AppData/Local/Temp/3e26e8e7aa5f147d0c6c7ae71efc007220170215-7312-1bv14wq.txt
Extracted source (around line #24):
def create
#article = Article.new(article_params) #line 24 here
if #article.save
redirect_to #article
How do I upload attachments with paperclip on windows without getting error, that the new file already exists?
Ran into a similar issue with this before, and it took a bit of searching, but here's where the problem was for tempfiles and Ruby on Windows.
C:\<path_to_ruby_file>\lib\ruby\<version>\tempfile.rb
Based on this post: https://www.ruby-forum.com/topic/187311
Our team was able to find the problem.
While they have a solution, we ended up writing our own.
You want (~Line 204):
def unlink
#----ADDED THIS LINE---#
return if #unlinked
#-----END ADDED LINE----#
begin
File.unlink(#tmpfile.path)
rescue Errno::ENOENT
rescue Errno::EACCES
# may not be able to unlink on Windows; just ignore
return
end
ObjectSpace.undefine_finalizer(self)
#unlinked = true
end
alias delete unlink
If you are still getting this error, let me know! Additionally, if you could check that the content of the tempfile is what you expect, that might be useful.

Operation not supported on socket # rb_sysopen

I upgraded my mac o/s to Yosemite.
After the upgrade I tried to work on a project that is a jekyll site. I ran jekyll serve, and received the following error:
jekyll 2.5.3 | Error: Operation not supported on socket # rb_sysopen
Any ideas what the issue could be?
I had the same problem and I got this solved by removing runctl file from the base directory.
I had the same problem:
jekyll 3.3.1 | Error: Operation not supported on socket # rb_sysopen - /Users/fanybo/Library/Application Support/Google/Chrome/App Shim Socket
I was running the server on the root directory, then I changed the directory, and changed the browser, now it works!

Resources