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

Show-Karma -Contemplate breaks after Classes #467

Closed
DEberhardt opened this issue Feb 6, 2022 · 12 comments
Closed

Show-Karma -Contemplate breaks after Classes #467

DEberhardt opened this issue Feb 6, 2022 · 12 comments
Labels
Category-Koans Invoking the Great Doubt Issue-Discussion Let's talk about it!

Comments

@DEberhardt
Copy link
Contributor

Describe "Koan Bug, Issue, or Help Request"

Show-Karma breaks down after classes

  • 311 Classes
  • ? XML
  • 320 Regular Expressions

Context "The Problematic Assertions"

Show-Karma -Contemplate fails after Classes

Context "Your Attempts"

    Welcome, seeker of enlightenment.
    Let us observe your karma...

Describing "About XML" has damaged your karma.

    You have not yet reached enlightenment.

    The answers you seek...

Expected strings to be the same, but they were different.
Expected length: 11
Actual length:   4
Strings differ at index 0.
Expected: 'Hello world'
But was:  '____'

    Please meditate on the following code:

× It "can cast a string to an XML document"
at <ScriptBlock>, C:\Users\David\PSKoans\Constructs and Patterns\AboutXml.Koans.ps1: line 28
28:             '____' | Should -Be $xml.DocumentRoot.element

    ▌ No one is injured but by himself.

    You examine the path beneath your feet...

 [AboutXml]: [―――――――――――――――――――――――――――――――――――――――――] 0/30

 [Total]: [■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■―――――――――――――――――――――――――――――] 425/682

Run 'Show-Karma -Meditate' to begin your meditations.


 599.491s  David  C:\                                                                                     13:28:58Show-Karma -Contemplate
Resolve-Path : Cannot bind argument to parameter 'Path' because it is null.
At C:\Users\David\Documents\WindowsPowerShell\Modules\PSKoans\0.67.1\Public\Show-Karma.ps1:124 char:50
+                     '"{0}":{1}' -f (Resolve-Path $FilePath), $LineNum ...
+                                                  ~~~~~~~~~
    + CategoryInfo          : InvalidData: (:) [Resolve-Path], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.ResolvePath
   Command

 David  C:\                                                                                                13:29:04Get-Module PsKoans -ListAvailable


    Directory: C:\Users\David\Documents\WindowsPowerShell\Modules


ModuleType Version    Name                                ExportedCommands
---------- -------    ----                                ----------------
Script     0.67.1     PSKoans                             {Get-Blank, Get-Karma, Get-PSKoan, Get-PSKoanLocation...}


 David  C:\                                                                                                13:29:52Show-Karma -Contemplate
 318.704s  David  C:\  ERROR                                                                             13:35:26Show-Karma -Contemplate
Invoke-Koan : Cannot remove variable Test because the variable has been optimized and is not removable. Try using the
Remove-Variable cmdlet (without any aliases), or dot-sourcing the command that you are using to remove the variable.
At C:\Users\David\Documents\WindowsPowerShell\Modules\PSKoans\0.67.1\Public\Get-Karma.ps1:111 char:32
+                 $PesterTests = Invoke-Koan @{
+                                ~~~~~~~~~~~~~~
    + CategoryInfo          : WriteError: (Test:String) [Invoke-Koan], SessionStateUnauthorizedAccessException
    + FullyQualifiedErrorId : VariableNotRemovableRare,Invoke-Koan

Invoke-Koan : No modules were removed. Verify that the specification of modules to remove is correct and those modules
exist in the runspace.
At C:\Users\David\Documents\WindowsPowerShell\Modules\PSKoans\0.67.1\Public\Get-Karma.ps1:111 char:32
+                 $PesterTests = Invoke-Koan @{
+                                ~~~~~~~~~~~~~~
    + CategoryInfo          : ResourceUnavailable: (:) [Invoke-Koan], InvalidOperationException
    + FullyQualifiedErrorId : Modules_NoModulesRemoved,Invoke-Koan595.976s  David  C:\                                                                                     13:51:05

Context "Additional Information"

Did I now miss out on XML? Did something break here?

@DEberhardt DEberhardt added Category-Koans Invoking the Great Doubt Issue-Discussion Let's talk about it! labels Feb 6, 2022
@vexx32
Copy link
Owner

vexx32 commented Feb 6, 2022

Woah, that is a weird one. Can you try Reset-PSKoan -Topic AboutXml? And also please send over your local copies of the files for AboutClasses and AboutXml topics!

@DEberhardt
Copy link
Contributor Author

DEberhardt commented Feb 6, 2022

I did find the Reset CmdLet

AboutClasses.Koans.ps1.txt
AboutXml.Koans.ps1.txt
The AboutXML does not look right.

After Reset, it now is back to normal:
AboutXml.Koans.ps1.txt

Still contemplating, will report back once Show-Karma provides output

@DEberhardt
Copy link
Contributor Author

Looks OK now.
Describing "About XML" has damaged your karma.
:)

@vexx32
Copy link
Owner

vexx32 commented Feb 6, 2022

Thanks!

@indented-automation have you seen that happen before, by any chance?

@DEberhardt
Copy link
Contributor Author

DEberhardt commented Feb 6, 2022

show-Karma -Contemplate
Resolve-Path : Cannot bind argument to parameter 'Path' because it is null.
At C:\Users\David\Documents\WindowsPowerShell\Modules\PSKoans\0.67.1\Public\Show-Karma.ps1:124 char:50
+                     '"{0}":{1}' -f (Resolve-Path $FilePath), $LineNum ...
+                                                  ~~~~~~~~~
    + CategoryInfo          : InvalidData: (:) [Resolve-Path], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.ResolvePath
   Command

that still is there... and now the AboutXML.ps1 is broken again. weird.

@indented-automation
Copy link
Contributor

Any chance you can share your library?

Reset is quite difficult if the file it's attempting to reset has syntax errors. It's reliant on AST to parse, locate, and replace parts. Resetting the entire file should be more successful. Would need a sample to debug it though.

@DEberhardt
Copy link
Contributor Author

Can do, what do you need and how/where should I upload it?

@DEberhardt
Copy link
Contributor Author

Now that I have started to work on XMLs and read it, I think I might have a clue as to why it breaks, maybe even a hint to resolve it:
Show-Karma is executing the code and post that the ps1 file content is this:

<documentRoot>
    <element>This is still a short XML file</element>
</documentRoot>

This is present in the file here:

        It 'is much faster to use the Load method of XmlDocument for large files' {
            Set-Content -Path $path -Value @'
<documentRoot>
    <element>This is still a short XML file</element>
</documentRoot>
'@

does $Path here point to its own file instead of to the TestDrive?
The previous assertion (It 'can convert output from Get-Content to an XML document' {) has a Join-Path in front, is that missing in It 'is much faster to use the Load method of XmlDocument for large files'

        It 'can convert output from Get-Content to an XML document' {
            <#
                It is often desirable to read an XML file to work with in PowerShell.

                Get-Content is often used to read XML content in as text.
            #>

            $path = Join-Path -Path $TestDrive -ChildPath document.xml
            Set-Content -Path $path -Value @'
<documentRoot>
    <element>A short XML file</element>
</documentRoot>
'@

@DEberhardt
Copy link
Contributor Author

ok. this works now for me

The current I think also would resolve this:

    BeforeAll {
        $path = Join-Path $TestDrive -ChildPath document.xml
    }
    

Closing :)

@vexx32
Copy link
Owner

vexx32 commented Feb 20, 2022

Glad you got it sorted! We should probably fix this as well, so reopening for now until we get it sorted. Feel free to unsubscribe from the issue if you don't wanna need to get notifs for it in future. 💖

@vexx32 vexx32 reopened this Feb 20, 2022
@DEberhardt
Copy link
Contributor Author

oh. I thought I close it, because I spotted that the fix (the BeforeAll statement) you have already in the document (just not in the one I download by using the Reset)

@vexx32
Copy link
Owner

vexx32 commented Feb 21, 2022

Ah, you're right, good point. Looks like we just need to get that into a release of the module at some point. Cheers! 😁

@vexx32 vexx32 closed this as completed Feb 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Category-Koans Invoking the Great Doubt Issue-Discussion Let's talk about it!
Projects
None yet
Development

No branches or pull requests

3 participants