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

cleanup joyent.rb #499

Merged
merged 1 commit into from
Nov 30, 2016
Merged

cleanup joyent.rb #499

merged 1 commit into from
Nov 30, 2016

Conversation

bahamas10
Copy link
Contributor

  • condense code
  • touch up style
  • don't stat(2) before open(2)

@thommay
Copy link
Contributor

thommay commented May 5, 2015

This all looks sane to me 👍 @chef/client-core

else
nil
end
::File.read("/opt/local/etc/pkg_install.conf").strip.split("=", 2).last rescue nil
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we make this rescue more specific? The way it's written now we'll rescue anything in .strip.split("=", 2).last when really we just want to rescue ENOENT and EACCES on the file read.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@danielsdeleo is it proper for an ohai plugin to have an uncaught exception? i figured the goal was to avoid that

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ohai catches all exceptions at a higher layer, which I dislike but we can't change that now. So any uncaught exception in a plugin will be rescued and cause a debug message to be printed, so if this plugin were to fail because, say, we had unexpected content in /opt/local/etc/pkg_install.conf, at least you would be able to get some feedback about why you suddenly didn't get the ohai data you expected. Which illustrates why I prefer not to do "blind" rescues like this (except in special cases), it hides or obfuscates the true source of the problem when something goes wrong.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah ok, i wasn't aware of ohai capturing all exceptions.

would it be best to remove the rescue statement completely then? I think it's just as much of a problem if /opt/local/etc/pkg_install.conf doesn't exist, as it is if it contains garbage data.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You'd be the person to know that better than me. Are we on a fundamentally broken system if /opt/local/etc/pkg_install.conf doesn't exist? Or is it a normal thing?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah good point, i'll make changes and push up a new commit.

(no, the system is not fundamentally broken in that case, so i'll modify the code to reflect that)

- condense code
- touch up style
- don't stat(2) before open(2)
lines << line
end
end
data = ::File.read("/etc/product") rescue nil
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You'll need to stub ::File.read("/etc/product") in the specs. The failures appear to be due to this line returning nil.

if data
data.strip.split("\n")
else
nil
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if returns nil if the condition is false.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Expeditor: Skip Version Bump Used to skip built_in:bump_version
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants