Skip to content

TypeNotFound when using classes #1064

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

Closed
abelal83 opened this issue Sep 3, 2018 · 4 comments
Closed

TypeNotFound when using classes #1064

abelal83 opened this issue Sep 3, 2018 · 4 comments

Comments

@abelal83
Copy link

abelal83 commented Sep 3, 2018

Steps to reproduce

class SecretComparer : System.Collections.IComparer {
    
    [int] $ChangeInDays = 7

    [bool] ShouldChangeSecret() {

        #throw "method not implemented"
        return $true
    }

    # this will compare if the secret is same
    [int] Compare([object] $obja, [object] $objb) {

        throw "method not implemented"
    }

}
using module .\Clarksons.Scripts.PlatformEngineering.DevsKeyVault.SecretComparer.psm1

class KeyVault {
    
    [string] $KeyVaultName

    KeyVault([string] $KeyVaultName, [SecretComparer] $comparer) {
    
        write-host $comparer
    }

}

$t = [SecretComparer]::new()
$x = [KeyVault]::new('gfdgfd', $t)

Expected behavior

This message should not appear as I'm loading classes into the sessions

Actual behavior

image

If an unexpected error was thrown then please report the full error details using e.g. $error[0] | Select-Object *

Environment data

> $PSVersionTable
Name                           Value
----                           -----
PSVersion                      5.1.14393.693
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.14393.693
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1

> (Get-Module -ListAvailable PSScriptAnalyzer).Version | ForEach-Object { $_.ToString() }
1.17.1
@bergmeister
Copy link
Collaborator

bergmeister commented Sep 3, 2018

This is by design and a limitation of the PowerShell parser, not PSScriptAnalyzer. In the future, we should address #1041 though and return a warning instead of a diagnostic record for Parser exceptions. cc @rjmholt

@abelal83
Copy link
Author

abelal83 commented Sep 3, 2018

Apols if this is a simple answer but how do I get around this in vscode? Right now I have several dozen green files in an otherwise clean powershell library due to this issue. I simply want to stop the files being displayed as having problems.

@bergmeister
Copy link
Collaborator

@abelal83 This is what issue #1041 is about: Currently those warnings cannot be suppressed other than filtered out via command line. Previously, PSSA failed completely, hence why it was decided to accept graceful parser errors but still display them as warnings to the user that only a part of the script could be analysed due to the limitation of the parser (PSSA completely relies on the parser in order to do its work). In hindsight, it was a mistake to return an object, which is being displayed as an issue in VSCode instead of just returning a warning and let VSCode deal with the display of the warning.

@abelal83
Copy link
Author

abelal83 commented Sep 4, 2018

@bergmeister gotcha, thank you for explaining.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants