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

[Bug] Invoke-DbatoolsFormatter behaves strangely in allcommands.ps1 #5800

Closed
1 of 5 tasks
jayvdb opened this issue Jun 21, 2019 · 3 comments · Fixed by #5815
Closed
1 of 5 tasks

[Bug] Invoke-DbatoolsFormatter behaves strangely in allcommands.ps1 #5800

jayvdb opened this issue Jun 21, 2019 · 3 comments · Fixed by #5815
Assignees

Comments

@jayvdb
Copy link

jayvdb commented Jun 21, 2019

Environmental information

(AppVeyor CI default worker; vs 2015 & 2017 images both tested)

Name                           Value                                           
----                           -----                                           
PSVersion                      5.1.14409.1012                                  
PSEdition                      Desktop                                         
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}                         
BuildVersion                   10.0.14409.1012                                 
CLRVersion                     4.0.30319.42000                                 
WSManStackVersion              3.0                                             
PSRemotingProtocolVersion      2.3                                             
SerializationVersion           1.1.0.1

Report

It looks like the allcommands.ps1 copy of Invoke-DbatoolsFormatter is broken, not having the same regexes as appear in the function Invoke-DbatoolsFormatter.ps1.

        $CBHRex = [regex]'(?smi)\s+<#[^#]*#>'
        $CBHStartRex = [regex]'(?<spaces>[ ]+)<#'
        $CBHEndRex = [regex]'(?<spaces>[ ]*)#>'
        $OSEOL = "`n"

vs in allcommands.ps1

        $CBHRex = [regex]'(?smi)\s+'
        $CBHStartRex = [regex]'(?<spaces>[ ]+)'
        $OSEOL = "`n"

My guess is that <#..#> is getting swallowed by some post-processor. A bit ironic that it was intended to solve a bug ... #4373

Host used

  • powershell.exe
  • ISE
  • VS Code
  • Other (please specify)

If anything other than powershell.exe was used, please confirm that you can duplicate the issue with powershell.exe

  • Still buggy in powershell.exe

Errors Received

You cannot call a method on a null-valued expression.
At C:\Program Files\WindowsPowerShell\Modules\dbatools\1.0.0\allcommands.ps1:44709 char:21
+ ...                  $newCBH = $CBHEndRex.Replace($CBH, "$startSpaces#>")
+                      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull
 

Steps to Reproduce

appveyor.yml

image: Visual Studio 2015

platform:
  - x86
  - x64

install:
  # Show initial state
  - powershell -c "$PSVersionTable"
  - echo %PATH%
  - echo %PSModulePath%
  - choco install PSScriptAnalyzer dbatools

build: false  # Not a C# project, build stuff at the test step instead.

test_script:
  - ps: echo "echo foo" > foo.ps1

        cat foo.ps1

        Invoke-DbatoolsFormatter foo.ps1

  - "set DBATOOLS=C:\\Program Files\\WindowsPowerShell\\Modules\\dbatools\\1.0.0"
  - ps: echo "echo foo" > foo.ps1

        cat foo.ps1

        . "$env:DBATOOLS\internal\functions\flowcontrol\Stop-Function.ps1"

        . "$env:DBATOOLS\internal\functions\flowcontrol\Test-FunctionInterrupt.ps1"

        . "$env:DBATOOLS\functions\Invoke-DbatoolsFormatter.ps1"

        Invoke-DbatoolsFormatter foo.ps1

Expected Behavior

choco package should work

Actual Behavior

it didnt, and the source appears to be the 1.0 zip file at https://github.com/sqlcollaborative/dbatools/archive/1.0.0.zip

@potatoqualitee
Copy link
Member

interesting! thank you. @StartAutomating can you please take a look?

@potatoqualitee
Copy link
Member

will fix with the following, likely tomorrow

lines 45-47
$CBHRex = [regex]'(?smi)\s+\<\#[^#]*\#\>'
       $CBHStartRex = [regex]'(?<spaces>[ ]+)\<\#'
       $CBHEndRex = [regex]'(?<spaces>[ ]*)\#\>'
should do it

@potatoqualitee
Copy link
Member

Thanks to @StartAutomating for the solution

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

Successfully merging a pull request may close this issue.

3 participants