Skip to content

Fix NameError in custom_attrs sample hook - #104

Closed
rootkiller6788 wants to merge 1 commit into
facebook:mainfrom
rootkiller6788:fix-custom-attrs-tmpfile
Closed

Fix NameError in custom_attrs sample hook#104
rootkiller6788 wants to merge 1 commit into
facebook:mainfrom
rootkiller6788:fix-custom-attrs-tmpfile

Conversation

@rootkiller6788

Copy link
Copy Markdown

Summary

The custom_attrs sample hook has referenced Tmpfile.new since it was added in 2017 (f4d6c28), but Tmpfile is not a constant Ruby defines anywhere — the stdlib tempfile class is Tempfile. As written, the hook crashes with

NameError: uninitialized constant CustomAttributes::Tmpfile

every time --custom-attr is passed on the command line, because pre_start runs Tmpfile.new('attributes') before the chef run starts.

This fixes the typo (TmpfileTempfile) and adds the missing require 'tempfile' so the sample hook actually works out of the box.

Verification

  • Tmpfile appears nowhere else in the repository and is not a Ruby stdlib class; Tempfile is the correct class (it is already used correctly in chefctl/src/spec/chefctl_spec.rb).
  • All Tempfile methods used by the hook — new, write, close, path, unlink — are part of the Tempfile API.
  • Reachable path: chefctl --custom-attr → CLI parsing sets @custom_attrChefctl::Plugin.get_plugin.pre_startTmpfile.new raises NameError.

Test plan

Static verification only; no Ruby runtime available locally. The change is a one-line constant rename plus a require.

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
@meta-cla meta-cla Bot added the CLA Signed label Aug 22, 2026
@jaymzh

jaymzh commented Aug 22, 2026

Copy link
Copy Markdown
Collaborator

This looks good, but it's still marked as a draft.

@rootkiller6788
rootkiller6788 marked this pull request as ready for review August 23, 2026 07:43
@rootkiller6788

Copy link
Copy Markdown
Author

Thanks for the review! I’ll take this out of draft mode now so it can be merged.

@jaymzh

jaymzh commented Aug 23, 2026

Copy link
Copy Markdown
Collaborator

@rootkiller6788 did you intentionally close this?

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.

2 participants