PowerShell / PowerShell/PSScriptAnalyzer
Cannot access a closed file
まだ誰も着手していません。
- 主要言語
- C#
- スター
- 2.2k
- フォーク
- 414
- 平均マージ
- 13時間 1分
- マージ済み PR(30日)
- 2
説明
I'm occasionally getting this error on running Invoke-ScriptAnalyzer with v 1.6.0
Invoke-ScriptAnalyzer : Cannot access a closed file.
The Full Error Object is
writeErrorStream : True
PSMessageDetails :
Exception : System.ObjectDisposedException: Cannot access a closed file.
at System.IO.__Error.FileNotOpen()
at System.IO.FileStream.Flush(Boolean flushToDisk)
at System.IO.StreamWriter.Flush(Boolean flushStream, Boolean flushEncoder)
at System.Management.Automation.Host.TranscriptionOption.Dispose()
at System.Management.Automation.Host.PSHostUserInterface.StopAllTranscribing()
at System.Management.Automation.Runspaces.LocalRunspace.DoCloseHelper()
at System.Management.Automation.Runspaces.RunspaceBase.CoreClose(Boolean syncCall)
at System.Management.Automation.Runspaces.LocalRunspace.Close()
at System.Management.Automation.Runspaces.LocalRunspace.Dispose(Boolean disposing)
at System.Management.Automation.PowerShell.Dispose(Boolean disposing)
at Microsoft.Windows.PowerShell.ScriptAnalyzer.Helper.GetModuleManifest(String filePath, IEnumerable`1& errorRecord)
at Microsoft.Windows.PowerShell.ScriptAnalyzer.BuiltinRules.MissingModuleManifestField.<AnalyzeScript>d__0.MoveNext()
at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
at Microsoft.Windows.PowerShell.ScriptAnalyzer.ScriptAnalyzer.<>c__DisplayClass63_0.<AnalyzeSyntaxTree>b__1()
TargetObject : C:\Users\Ryan\Onedrive\Github\PowerShellModules\PesterHelpers\PesterHelpers.psd1
CategoryInfo : InvalidOperation: (C:\Users\Ryan\O...terHelpers.psd1:String) [Invoke-ScriptAnalyzer], ObjectDisposedException
FullyQualifiedErrorId : RULE_ERROR,Microsoft.Windows.PowerShell.ScriptAnalyzer.Commands.InvokeScriptAnalyzerCommand
ErrorDetails :
InvocationInfo : System.Management.Automation.InvocationInfo
ScriptStackTrace : at <ScriptBlock>, C:\Users\Ryan\Onedrive\Github\PowerShellModules\PesterHelpers\PesterHelpers.tests.ps1: line 34
at Invoke-Test, C:\Program Files\WindowsPowerShell\Modules\Pester\3.4.0\Functions\It.ps1: line 253
at ItImpl, C:\Program Files\WindowsPowerShell\Modules\Pester\3.4.0\Functions\It.ps1: line 203
at It, C:\Program Files\WindowsPowerShell\Modules\Pester\3.4.0\Functions\It.ps1: line 117
at <ScriptBlock>, C:\Users\Ryan\Onedrive\Github\PowerShellModules\PesterHelpers\PesterHelpers.tests.ps1: line 33
at Describe, C:\Program Files\WindowsPowerShell\Modules\Pester\3.4.0\Functions\Describe.ps1: line 100
at <ScriptBlock>, C:\Users\Ryan\Onedrive\Github\PowerShellModules\PesterHelpers\PesterHelpers.tests.ps1: line 15
at <ScriptBlock>, C:\Program Files\WindowsPowerShell\Modules\Pester\3.4.0\Pester.psm1: line 279
at Invoke-Pester, C:\Program Files\WindowsPowerShell\Modules\Pester\3.4.0\Pester.psm1: line 292
at <ScriptBlock>, <No file>: line 1
PipelineIterationInfo : {0, 1}
This seems only to fire occasionally on the following rules with the error message given above
PSUseToExportFieldsInManifest
PSMissingModuleManifestField
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
スタックトレースに示されている Microsoft.Windows.PowerShell.ScriptAnalyzer.Helper.GetModuleManifest と MissingModuleManifestField および PSUseToExportFieldsInManifest ルールから始めます。参照されている PesterHelpers.psd1 または別のモジュールマニフェストに対して Invoke-ScriptAnalyzer を再現し、その後、エラーに示されている runspace と transcription の破棄を追跡します。これらのルールが ObjectDisposedException を断続的に報告しなくなれば完了です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- csharp, powershell
- 領域
- devtools
- issue の種類
- バグ
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 35/100