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

chef_version metadata violation raises incorrect error #9038

kimbernator opened this issue Oct 31, 2019 · 1 comment · Fixed by #9083


Copy link

@kimbernator kimbernator commented Oct 31, 2019


If a run-list includes a cookbook with a chef_version constraint that is not permissive of the version of chef infra client running, the error raised is incorrect due to an error in the code to finalize the run with an end message:

Running handlers:
[2019-10-31T13:22:15-05:00] ERROR: Running exception handlers
Running handlers complete
[2019-10-31T13:22:15-05:00] ERROR: Exception handlers complete
Chef Infra Client failed. 0 resources updated in 10 seconds
[2019-10-31T13:22:15-05:00] FATAL: NoMethodError: undefined method `filtered_collection' for nil:NilClass

Running chef-client -l trace reveals an attempt at re-raising the correct error, which is:

[2019-10-31T13:22:15-05:00] TRACE: Re-raising exception: Chef::Exceptions::CookbookChefVersionMismatch - Cookbook '<cookbook_name>' version '0.5.0' depends on chef version [">= 12.14", "< 15"], but the running chef version is 15.4.45

In these lines:


Lines 303 to 317 in b499e05

logger.trace("Re-raising exception: #{run_error.class} - #{run_error.message}\n#{run_error.backtrace.join("\n ")}")
# If we failed really early, we may not have a run_status yet. Too early for these to be of much use.
if run_status
run_status.exception = run_error
events.run_failed(run_error, run_status)
raise run_error
@run_status = nil

The exception is re-raised in a trace log, but line 308's run_failed call experiences its own error which is unhandled and results in all code until ensure (lines 310-312) not being executed and the CookbookChefVersionMismatch not being raised.

The unhandled error occurs when formatting the run ending message as a result of the updated_resources method in chef/resource_reporter.rb:

# get only the top level resources and strip out the subcollections
def updated_resources
@updated_resources ||= action_collection.filtered_collection(max_nesting: 0, up_to_date: false, skipped: false, unprocessed: false)

Changing line 186 to the following results in a chef-client failure that includes the more useful CookbookChefVersionMismatch error:

@updated_resources ||= action_collection&.filtered_collection(max_nesting: 0, up_to_date: false, skipped: false, unprocessed: false) || {}

(Changes being the & after action_collection to return nil instead of throwing a NoMethodError, and || {} at the end to assign {} to @updated_resources)

I am hesitant to submit a PR with this change since it feels like a cheap hack to resolve one specific error without addressing the fact that @action_collection is not being defined early enough for this error to be properly raised.

Chef Version


Platform Version

RHEL 6 and Windows Server 2008R2

Replication Case

Include a cookbook with chef_version constraints in metadata.rb that exclude the chef-client version running. Make sure cookbook synchronization is not disabled. No policy files.

Client Output

Included in description




This comment has been minimized.

Copy link

@lamont-granquist lamont-granquist commented Nov 1, 2019

thats the correct fix, can you submit the PR?

lamont-granquist added a commit that referenced this issue Nov 12, 2019
closes #9043
closes #9038

Signed-off-by: Lamont Granquist <>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
2 participants
You can’t perform that action at this time.