Fix NameError in custom_attrs sample hook - #104
Closed
rootkiller6788 wants to merge 1 commit into
Closed
Conversation
The custom_attrs sample hook references Tmpfile, which is not a Ruby constant. The Ruby stdlib tempfile class is Tempfile, so calling Tmpfile.new in pre_start raises a NameError whenever --custom-attr is passed. Fix the typo and add the missing require 'tempfile'. Signed-off-by: rootkiller6788
jaymzh
approved these changes
Aug 22, 2026
Collaborator
|
This looks good, but it's still marked as a draft. |
rootkiller6788
marked this pull request as ready for review
August 23, 2026 07:43
Author
|
Thanks for the review! I’ll take this out of draft mode now so it can be merged. |
Collaborator
|
@rootkiller6788 did you intentionally close this? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The
custom_attrssample hook has referencedTmpfile.newsince it was added in 2017 (f4d6c28), butTmpfileis not a constant Ruby defines anywhere — the stdlib tempfile class isTempfile. As written, the hook crashes withevery time
--custom-attris passed on the command line, becausepre_startrunsTmpfile.new('attributes')before the chef run starts.This fixes the typo (
Tmpfile→Tempfile) and adds the missingrequire 'tempfile'so the sample hook actually works out of the box.Verification
Tmpfileappears nowhere else in the repository and is not a Ruby stdlib class;Tempfileis the correct class (it is already used correctly inchefctl/src/spec/chefctl_spec.rb).Tempfilemethods used by the hook —new,write,close,path,unlink— are part of theTempfileAPI.chefctl --custom-attr→ CLI parsing sets@custom_attr→Chefctl::Plugin.get_plugin.pre_start→Tmpfile.newraisesNameError.Test plan
Static verification only; no Ruby runtime available locally. The change is a one-line constant rename plus a
require.