majkinetor / au

Chocolatey Automatic Package Updater Module
GNU General Public License v2.0
227 stars 71 forks source link

An exception 'Cannot run a document in the middle of a pipeline' is fired when running update and the package is not created. #267

Closed moh-hassan closed 2 years ago

moh-hassan commented 2 years ago

I used the package dngrep on the url: https://github.com/majkinetor/au-packages/tree/master/dngrep
When I tried to run upadte, I get an error

update : Cannot run a document in the middle of a pipeline: C:\windows\system32\choco.
At C:\MyTest\dngrep\update.ps1:41 char:1
+ update -ChecksumFor none -NoCheckChocoVersion 
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (C:\windows\system32\choco:String) [Up 
   date-Package], RuntimeException
    + FullyQualifiedErrorId : CantActivateDocumentInPipeline,Update-Package 

The update is ok but the package is not created and I had to create it manually 'choco pack'. Also the msi files are downloaded in the folder tools. au version 2021.7.18 Powershel version: 5 or 7

How to avoid this Exception and auto delete the msi files to create the package without them downloaded binaries.

Update: I traced the error and found the root rror:

InvalidOperation: C:\Program Files\WindowsPowerShell\Modules\AU\2021.7.18\Public\Update-Package.ps1:257:13
Line |                                                                                                                         
 257 |              choco pack --limit-output | result
     |              ~~~~~~~~~~~~~~~~~~~~~~~~~                                                                                  
     | Cannot run a document in the middle of a pipeline: C:\windows\system32\choco.

When I try to run this line on my shell: choco pack --limit-output, PowerShell open a dialog "how do you want to open this file" to select a program. I had to add .exe extension to command like this to be executed without the dialog: choco.exe pack --limit-output

It seems that 'choco' is not defined as exe program, and this may be related to the cause of the issue.

majkinetor commented 2 years ago

That is certainly something not normal on your system. Perhaps reinstall chocolatey ?

> Get-Command choco

CommandType     Name                                               Version    Source
-----------     ----                                               -------    ------
Application     choco.exe                                          0.12.1.0   C:\ProgramData\chocolatey\bin\choco.exe
moh-hassan commented 2 years ago

@majkinetor Thanks for reply and support. I upgraded chocolatey software to v 1.1.0. Now, when checking Get-Command choco, I get version '0.12.1.0' I run update, and now, It's fine, No exception and the package is created. 👍

Just, one thing, I find two binary files msi on the package tools folder which were downloaded during checksum. I had to add script in global:au_AfterUpdate to remove them. Is there a built-in method to drop these binaries after checksum calculation?

majkinetor commented 2 years ago

Regardin binaries, its a package related thing. I remove them in my packages.