Skip to content

Commit 07b417b

Browse files
authored
fix(workflow-code): list container properties and outputs when an unknown name has no near match (#10631)
* fix(workflow-code): list container properties and outputs when an unknown name has no near match E_UNKNOWN_SUBFLOW_PROPERTY and the container branch of W_UNKNOWN_OUTPUT_PATH fell back to no hint when didYouMean found nothing; they now list what the loop or parallel exposes, mirroring unknownOutputHint. Also corrects the CONTAINER_OUTPUTS TSDoc to name OUTPUT_PROPERTIES. * fix(workflow-code): list only container outputs readable from the reference site
1 parent cfe84c6 commit 07b417b

2 files changed

Lines changed: 35 additions & 3 deletions

File tree

‎packages/workflow-code/src/compile/grammar.test.ts‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -607,6 +607,18 @@ describe('warnings that never block a compile', () => {
607607
)
608608
expect(result.diagnostics.map((d) => d.code)).not.toContain('W_UNKNOWN_OUTPUT_PATH')
609609
})
610+
611+
it('lists only the outputs readable from outside a container when an unknown one has no near name', () => {
612+
const text = source(
613+
"const l = loop.forEach('L', { collection: [] }, (p) => {})\nconst b = api('B', { url: l.value })"
614+
)
615+
expectDiagnostic(
616+
run(text),
617+
'W_UNKNOWN_OUTPUT_PATH',
618+
locate(text, 'l.value'),
619+
'A loop has: results, result.'
620+
)
621+
})
610622
})
611623

612624
describe('errors, each with its code, location and hint', () => {
@@ -725,6 +737,13 @@ describe('errors, each with its code, location and hint', () => {
725737
'p.curentItem',
726738
'Did you mean p.currentItem?',
727739
],
740+
[
741+
'an unknown loop property with no near name',
742+
"const l = loop.forEach('L', { collection: [] }, (p) => {\n const a = api('A', { url: p.value })\n p.to(a)\n})",
743+
'E_UNKNOWN_SUBFLOW_PROPERTY',
744+
'p.value',
745+
'A loop has: p.index, p.currentItem, p.items, p.iteration, p.item.',
746+
],
728747
[
729748
'subflow data on a block that is not a container',
730749
"const s = slack.sendMessage('S', { authMethod: 'oauth', text: 'x' }, { subflowData: { count: 2 } })",

‎packages/workflow-code/src/compile/values.ts‎

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ export const SDK_VALUE_FUNCTIONS: ReadonlySet<string> = new Set([
133133
'vars',
134134
] as const satisfies readonly SdkCoreExport[])
135135

136-
/** Named-form container outputs (`LoopResolver` / `ParallelResolver` `KNOWN_PROPERTIES`). */
136+
/** Named-form container outputs (`LoopResolver` / `ParallelResolver` `OUTPUT_PROPERTIES`). */
137137
const CONTAINER_OUTPUTS = ['results', 'result']
138138

139139
function rejectNode(ctx: CompileContext, node: Node, site?: ValueSite): null {
@@ -818,7 +818,18 @@ function checkOutputPath(
818818
'W_UNKNOWN_OUTPUT_PATH',
819819
`A ${containerKind} has no output ${first.name}.`,
820820
at,
821-
{ hint: () => didYouMean(first.name, known), blockKey }
821+
{
822+
hint: () => {
823+
const readable = known.filter(
824+
(name) =>
825+
!readsIterationOutOfScope(blockKey, target, name, (key) => scopeNodeOf(ctx, key))
826+
)
827+
return (
828+
didYouMean(first.name, readable) ?? `A ${containerKind} has: ${readable.join(', ')}.`
829+
)
830+
},
831+
blockKey,
832+
}
822833
)
823834
}
824835
if (first.kind === 'name') checkIterationScope(ctx, at, blockKey, target, first.name)
@@ -1128,7 +1139,9 @@ function subflowScopeRef(
11281139
`A ${kind} has no property ${property ?? '(none)'}.`,
11291140
rangeOf(ctx, node),
11301141
{
1131-
hint: didYouMean(property ?? '', known, (name) => `${label}.${name}`),
1142+
hint:
1143+
didYouMean(property ?? '', known, (name) => `${label}.${name}`) ??
1144+
`A ${kind} has: ${known.map((name) => `${label}.${name}`).join(', ')}.`,
11321145
blockKey: site.decl.key,
11331146
}
11341147
)

0 commit comments

Comments
 (0)