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

JSON resource's error message is missing filename when file is not found #1358

Closed
makotots opened this issue Dec 12, 2016 · 2 comments · Fixed by #1366
Closed

JSON resource's error message is missing filename when file is not found #1358

makotots opened this issue Dec 12, 2016 · 2 comments · Fixed by #1366
Labels
Type: Bug Feature not working as expected

Comments

@makotots
Copy link
Contributor

Hello!

Description

In an example below, I expect filename is printed in its error message:

% inspec exec demo.rb
(snip)
  Json /nonexistent.json
     ↺  Can't find file ""    <---- here

% cat demo.rb
describe json('/nonexistent.json') do
  its('name') { should eq 'hello' }
end
%

InSpec and Platform Version

InSpec version : 1.7.1
Platform Version: macOS Sierra 10.12.1

Replication Case

See demo.rb above - run a test with a non-existent json filename.

Possible Solutions

According to resources/json.rb, the error message refers to @conf_path, which is undefined.

        @path = opts
        @file = inspec.file(@opts)
        @file_content = @file.content

        # check if file is available
        if !@file.file?
          skip_resource "Can't find file \"#{@conf_path}\""
          return @params = {}
        end

I believe the pull request #1345 is almost correct to handle this (successful unit test included in the PR) but I couldn't figure out why one of the functional test failed in Travis CI. I ran the same test using Travis CI several times, which did not reproduce the same test failure.

Stacktrace

No stacktrace is produced.

Thank you for your help in advance.

@chris-rock
Copy link
Contributor

@makotots Great finding. Are you pushing up your PR again? I am happy to help with the unit tests.

@makotots
Copy link
Contributor Author

@chris-rock Can you take a look at this PR (1363, not 1345) and help with the failed functional test? Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Bug Feature not working as expected
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants