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

Don't crash on CIM classes with no superclass #1046

Merged
merged 7 commits into from
Sep 13, 2018

Conversation

edyoung
Copy link
Contributor

@edyoung edyoung commented Jul 26, 2018

PR Summary

Fix #982 by checking for null on superclass property.

PR Checklist

Note: Tick the boxes below that apply to this pull request by putting an x between the square brackets. Please mark anything not applicable to this PR NA.

  • PR has a meaningful title
    • Use the present tense and imperative mood when describing your changes
  • Summarized changes
  • User facing documentation needed
  • Change is not breaking
  • Make sure you've added a new test if existing tests do not effectively test the code changed
  • This PR is ready to merge and is not work in progress
    • If the PR is work in progress, please add the prefix WIP: to the beginning of the title and remove the prefix when the PR is ready

@edyoung
Copy link
Contributor Author

edyoung commented Jul 26, 2018

Bergmeister's PR #985 addresses same issue, I am agnostic about which one to take. Would be nice to fix though...

@bergmeister
Copy link
Collaborator

bergmeister commented Jul 26, 2018

My PR is still WIP because I also wanted to remove the empty catch block, which then caused test failures on Linux, therefore, I think it is OK to take your PR first with only the minimal changes for fixing the NullReferenceException. But I think we should add a test case though for the bug that this PR fixes before merging the PR despite the fix being trivial.

@bergmeister
Copy link
Collaborator

bergmeister commented Jul 26, 2018

The error in the AppVeyor WMF4 build is actually due to the recent breaking change with TLS 1.2 here: dotnet/announcements#77
I opened a PR with a fix for it here: #1047 and merged it into your branch

Copy link
Member

@JamesWTruher JamesWTruher left a comment

Choose a reason for hiding this comment

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

I think the change is great, but I would really like to have a test for this.

@edyoung
Copy link
Contributor Author

edyoung commented Aug 26, 2018

OK, added a test case.

@edyoung
Copy link
Contributor Author

edyoung commented Aug 28, 2018

@JamesWTruher @bergmeister can we merge this now?

@bergmeister
Copy link
Collaborator

Sorry, I will review this the next days (I want to test that that the added test would actually fail) but it looks OK otherwise.

Copy link
Collaborator

@bergmeister bergmeister left a comment

Choose a reason for hiding this comment

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

@edyoung There are 2 problems with the added test:

  • The test does not fail when using a version of PSSA without this fix. This is due to PSSA throwing a non-terminating error. A solution that to assert against this is the following pattern:
            $exceptionThrown = $false
            try {
                $violations = Invoke-ScriptAnalyzer -Path $noParentClassFilepath -IncludeRule $ruleName -ErrorAction Stop
                $violations.Count | Should -Be 0
            }
            catch {
                $exceptionThrown = $true
            }
            $exceptionThrown | Should -Be $false
  • The test uses checked in files for testing, which is not good as it makes the test code less readable and will add to the (already existing) clutter of the code base. Please use Pester's built in functionality for file operation isolation that also handles the cleanup of it: https://github.com/pester/Pester/wiki/TestDrive

@edyoung
Copy link
Contributor Author

edyoung commented Sep 6, 2018

Added -ErrorAction Stop - the additional try/catch/should check isn't needed as far as I can see - Pester fails the test because a terminating error occurs.

Changed the test data to be inline, but TBH I don't really think it's an improvement.

Copy link
Collaborator

@bergmeister bergmeister left a comment

Choose a reason for hiding this comment

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

LGTM and tested that test would actually fail in case of a regression

@edyoung
Copy link
Contributor Author

edyoung commented Sep 12, 2018

@JamesWTruher wondered if [path.io]::combine("testdrive:", ...) would do the right thing on linux. I tried it, and I believe it does, but changed to Join-Path anyway. Also, turns out this rule basically doesn';t work on linux anyway because DscClassCache.Initialize() throws and the rest of the rule doesn't do anything. So I marked the test to be skipped on linux and mac like the others in this file.

@edyoung
Copy link
Contributor Author

edyoung commented Sep 13, 2018

@JamesWTruher if you're ok with this please go ahead & merge (FYI the main reason I care about this is that PowerShell Gallery script scanning process hits this exception fairly frequently and I want to cut the noise).

@bergmeister
Copy link
Collaborator

bergmeister commented Sep 13, 2018

@edyoung Since you have addressed the comment by @JamesWTruher and me about adding a test, I think it is OK to merge it in since the implementation has already been approved. Should there be any more tweaks to be made to the test, we can add it after this PR in order to speedup things for you.
@edyoung Is the PSGallery using a custom built version of PSSA or would you need a 1.18.0 release to receive those changes?

@bergmeister bergmeister merged commit a5571c5 into PowerShell:development Sep 13, 2018
bergmeister pushed a commit to bergmeister/PSScriptAnalyzer that referenced this pull request Mar 22, 2019
* Don't crash on CIM classes with no superclass

* ReTrigger CI by using better linq variable name

* add test case

* incorporate PR feedback

* tweak test for linux

* use join-path
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.

NullReferenceException analyzing xWebAdministration DSC resource
3 participants