continue and break without a local target - 41 sites, Invoke-DbaXEReplay replays nothing
メンテナーはふだん 2 日以内に返信
まだ誰も着手していません。
評価
- 難易度
- 5/5
- 見積もり時間
- 1週間以上
- 初心者へのやさしさ
- 25/100
調査の方向性
Start with the listed command sites in public/ and private/, especially Invoke-DbaXEReplay and the other public command defects; the issue provides their function names and line numbers. Read CLAUDE.md rule 1 and Get-DbaCommandStructureFinding in tests/dbatools.CommandStructure.ps1, then inspect the analyzer Describe and its exception mechanism. Done means the command defects and analyzer changes are handled in the stated order, fixtures cover local and nonlocal jump targets, and the rule text includes plain continue and break.
索引モデルが issue の本文から書いたものです。
説明
The problem
Rule 1 of the command invariants in CLAUDE.md demands a local target for Stop-Function -Continue, and the "command structure" Describe enforces it. A plain continue or break has the same problem, and nothing checks it. In a function or scriptblock without a loop, switch or trap of its own, PowerShell looks for the target up the call stack, across function boundaries, and a try/catch in between does not stop it.
A probe of a command with continue in its process block gave the same result on Windows PowerShell 5.1 and PowerShell 7.6:
| Caller | What happens |
|---|---|
| A plain call or a pipeline in a script, no loop | The whole script ends silently, with exit code 0. Neither the end block of the command nor the next statement of the caller runs. |
Inside a foreach of the caller |
The rest of that iteration of the loop of the caller is skipped, then the loop goes on. |
Found while working on #10801: Update-SqlPermission ended its database mapping part for a destination older than SQL Server 2005 with continue, so Sync-DbaLoginPermission lost its result rows. That one is fixed in #10801 (34a8ddc78).
How the list was made
An AST scan of public/ and private/ on development 900ba0347 (v2.9.1) for continue and break statements without a loop, switch or trap in the same function or scriptblock. It found 41 sites. The script is at the end. Lab checks ran on SQL03\SQL2019 under Windows PowerShell 5.1.
Defects in public commands (8 sites in 7 commands)
- Invoke-DbaXEReplay:113,
process:if ($InputObject.Name -notin $Event) { continue }. Piped from Read-DbaXEFile, as all three examples do, the first event that is not in-Eventends the pipeline. Theendblock, which runs sqlcmd, never runs, so nothing is replayed, and the calling script ends. The default of-Eventis'sql_batch_completed', 'rcp_completed', andrcp_completedis a typo ofrpc_completed, so every RPC event of a capture hits this. Lab: onerpc_completedevent followed by onesql_batch_completedevent gave no output, nothing was replayed, the line after the call never ran, exit code 0. The batch event alone is replayed. The test uses asql_batch_completedevent only. Fix:return, and the name of the event. - Invoke-DbaDbccFreeCache:137,
begin:-Operationhas the defaultFreeProcCache, but without an explicit-Operationthe command warns "You must specify an operation" and runscontinue. The default is never used, the command does nothing, and the calling script ends (lab: the warning, exit code 0, the next line did not run). Every example passes-Operation. Fix: use the default, orStop-Functionandreturnwith the guard inprocess(rule 3). - Find-DbaDbUnusedIndex:236,
process: a-Databasethat matches nothing warns "Database [...] was not found on [...]" and runscontinue(lab: the script ended after the warning). Fix:return. - Get-DbaDbCompatibility:88, Set-DbaDbCompatibility:99, Invoke-DbaDbUpgrade:155 and :160,
process: the parameter checks "You must specify either a SQL instance or pipe a database collection" and "You must explicitly specify a database ..." warn and runcontinue. Fix:return, orStop-Functionandreturn. - Get-DbaManagementObject:216, in the scriptblock that runs locally with
Invoke-Commandand remotely withInvoke-Command2: "No SMO versions found in GAC" runscontinue, which skips the output of the SNI modules after it ("always run this regardless of other conditions"). Locally the scriptblock runs in the same runspace, so thecontinuealso lands inforeach ($computer in $ComputerName.ComputerName)ofprocess. No SMO in the GAC is the normal case when SMO comes from dbatools.library. Lab, withMicrosoft.Data.SqlClient.SNI.x64.dllloaded: the command returned 4 rows and no SNI row; the same function without thecontinuereturned the SNI row as the fifth. Fix: delete thecontinue. Areturnwould skip the SNI output as well.
Defects in helpers, where the jump lands in the loop of the caller (17 sites)
- Update-SqlPermission:204: fixed in #10801 (34a8ddc78), see above.
- Copy-DbaDbMail:165, in
Copy-DbaDbMailConfig: after a failed copy of the configuration values, thecontinuein thecatchlands inforeach ($destinstance in $Destination)and skips the accounts, profiles, mail servers and Database Mail XPs of that destination, without a row for them (the failed row of the configuration is written). With-Typeit lands inswitch ($type)and only skips the refresh of the configuration values. - Copy-DbaLogin:255, 257, 261, 271, 281, 296, 313, 322, 335, 346, 356, 414, 424, 479, 506, in
Copy-Login: the exits for a login that is skipped or fails, each after its result row. They land inforeach ($destinstance in $Destination)ofprocessand skip the-SyncSaNameblock of that iteration. When every login of a run is skipped, for example because all of them exist and-Forceis not used,-SyncSaNamenever runs (from the code, not reproduced in the lab). The new-UpdateExistingpath of #10801 leaves withreturnfor that reason. To decide:returnin all 15, or an exception for a deliberate pattern.
Harmless, but they depend on the shape of the caller (3 sites)
- Copy-DbaRegServer:141, 152, 169, in
Invoke-ParseServerGroup: reachable only from the top-level call with-Group, which is the last statement offoreach ($store in $stores), so the effect is that of areturn. Areturnkeeps it that way when the caller changes.
Dead code (8 sites)
- Test-DbaLsnChain:70, 85, 93 and Test-DbaRestoreVersion:53, 72, 78, 84:
breakafterreturn $false. Invoke-Parallel:417:BreakafterThrow. Never reached, they can go.
Deliberate (5 sites)
- Stop-Function:248, 250, 270, 272: the
continueof-Continue,-ContinueLabeland-SilentlyContinue, the mechanism rule 1 is about. - private/scripts/updateTeppAsync.ps1:30,
Update-TeppCache: the stop flag of the tab completion updater ends thewhile ($true)loop of its caller, like the explicit check at line 70.
Proposal: extend rule 1 to plain continue and break
Get-DbaCommandStructureFinding in tests/dbatools.CommandStructure.ps1 already walks from a Stop-Function -Continue to its loop or switch in the same function or scriptblock and checks the label. The same walk for every ContinueStatementAst and BreakStatementAst, with trap as a target as well, would report a plain jump without a local target as a rule 1 finding. The exceptions use the existing mechanism ($dynamicContinueExceptions: file, function, exact number of sites, reason): at first Stop-Function (4) and Update-TeppCache (1), and Copy-Login (15) if those stay. Fixtures go into the analyzer Describe, and the text of rule 1 in CLAUDE.md names plain continue and break as well.
Order, as for #10794: first the fixes, one PR per command, then the check, which stays red until they are merged.
Scan script
# Lists continue and break statements without a loop, switch or trap in the same function or scriptblock.
$files = Get-ChildItem -Path .\public, .\private -Filter *.ps1 -Recurse
foreach ($file in $files) {
$ast = [System.Management.Automation.Language.Parser]::ParseFile($file.FullName, [ref]$null, [ref]$null)
$jumps = $ast.FindAll({
param($node)
$node -is [System.Management.Automation.Language.ContinueStatementAst] -or
$node -is [System.Management.Automation.Language.BreakStatementAst]
}, $true)
foreach ($jump in $jumps) {
$parent = $jump.Parent
$hasTarget = $false
while ($parent) {
if ($parent -is [System.Management.Automation.Language.LoopStatementAst] -or
$parent -is [System.Management.Automation.Language.SwitchStatementAst] -or
$parent -is [System.Management.Automation.Language.TrapStatementAst]) {
$hasTarget = $true
break
}
if ($parent -is [System.Management.Automation.Language.FunctionDefinitionAst] -or
$parent -is [System.Management.Automation.Language.ScriptBlockExpressionAst]) {
break
}
$parent = $parent.Parent
}
if (-not $hasTarget) {
$function = $jump.Parent
while ($function -and $function -isnot [System.Management.Automation.Language.FunctionDefinitionAst]) {
$function = $function.Parent
}
[PSCustomObject]@{
File = $file.Name
Line = $jump.Extent.StartLineNumber
Function = $function.Name
Statement = $jump.Extent.Text
}
}
}
}
This text was created by Claude and reviewed by Andreas Jordan.
- 主要言語
- PowerShell
- スター
- 2.9k
- フォーク
- 869
- 平均マージ
- 2日 4時間
- マージ済み PR(30日)
- 38
環境構築
このプロジェクトの開発コンテナを、あなたの GitHub アカウントでブラウザ上に起動します。
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
dataplat/dbatools のほかの issue
-
bugs life triage required
難易度 2/5 1〜3時間 初心者へのやさしさ 65/100
メンテナーはふだん 2 日以内に返信
-
bugs life triage required
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
メンテナーはふだん 2 日以内に返信
-
Invoke-DbaDbPiiScan - Fix broken PII patterns, add Nordic known names, and proposals for metadata-only scan and native classification対応中かも このイシューにリンクされたプルリクエストがオープン中、またはマージ済みです。 オープン
難易度 3/5 1〜2日 初心者へのやさしさ 35/100
メンテナーはふだん 2 日以内に返信
-
bugs life triage required
難易度 4/5 3〜5日 初心者へのやさしさ 48/100
dataplat/dbatools#10860 · コメント 1 件 ·
メンテナーはふだん 2 日以内に返信
-
bugs life Chrissy needed
難易度 3/5 半日 初心者へのやさしさ 38/100
メンテナーはふだん 2 日以内に返信
dataplat/dbatools の issue をすべて見る
似ている issue
-
難易度 1/5 1時間未満 初心者へのやさしさ 88/100
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
hanami/hanami-action#536 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
Sienna-Platform/PowerNetworkMatrices.jl#446 ·
メンテナーはふだん 1 日以内に返信
-
compatibility difficulty:easy prio:low
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
NatronGitHub/openfx-misc#385 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100