continue and break without a local target - 41 sites, Invoke-DbaXEReplay replays nothing
Los mantenedores suelen responder en 2 días
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 5/5
- Tiempo estimado
- Más de una semana
- Aptitud para principiantes
- 25/100
Línea de trabajo
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.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
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.
- Lenguaje dominante
- PowerShell
- Estrellas
- 2.9k
- Forks
- 869
- Merge medio
- 2 d 4 h
- PR fusionados (30 d)
- 38
Preparar el entorno
Inicia el contenedor de desarrollo del proyecto en tu navegador, con tu propia cuenta de GitHub.
- Sin Dockerfile ni archivo de Docker Compose
- Tiene una plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de dataplat/dbatools
-
bugs life triage required
Dificultad 2/5 1-3 horas Aptitud para principiantes 65/100
Los mantenedores suelen responder en 2 días
-
bugs life triage required
Dificultad 2/5 1-3 horas Aptitud para principiantes 75/100
Los mantenedores suelen responder en 2 días
-
Invoke-DbaDbPiiScan - Fix broken PII patterns, add Nordic known names, and proposals for metadata-only scan and native classificationPosiblemente ocupada Un pull request vinculado a esta issue está abierto o ya se fusionó. Abierto
Dificultad 3/5 1-2 días Aptitud para principiantes 35/100
Los mantenedores suelen responder en 2 días
-
bugs life triage required
Dificultad 4/5 3-5 días Aptitud para principiantes 48/100
dataplat/dbatools#10860 · 1 comentario ·
Los mantenedores suelen responder en 2 días
-
bugs life Chrissy needed
Dificultad 3/5 Medio día Aptitud para principiantes 38/100
Los mantenedores suelen responder en 2 días
Todos los issues de dataplat/dbatools
Issues similares
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 65/100
Los mantenedores suelen responder en 1 día
-
enhancement
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
Los mantenedores suelen responder en 1 día
-
fix(core): \.pluck() returns values in key insertion order instead of requested argument orderPosiblemente ocupada @ManyaS-Git la tomó hace 1 día. Abiertostatus:in-linear
Dificultad 2/5 1-3 horas Aptitud para principiantes 75/100
n8n-io/n8n#45027 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
[BUG]: chunkSource protocol stripping truncates URLs or reads an inner schemePosiblemente ocupada @Bensonbenyi la tomó hoy. Abierto
Dificultad 1/5 Menos de una hora Aptitud para principiantes 88/100
Mintplex-Labs/anything-llm#7338 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
lidofinance/validator-ejector#228 ·
Los mantenedores suelen responder en 1 día