diff --git a/packages/workflow-code/src/compile/grammar.test.ts b/packages/workflow-code/src/compile/grammar.test.ts index 5efabcfedf8..9a89f127777 100644 --- a/packages/workflow-code/src/compile/grammar.test.ts +++ b/packages/workflow-code/src/compile/grammar.test.ts @@ -607,6 +607,18 @@ describe('warnings that never block a compile', () => { ) expect(result.diagnostics.map((d) => d.code)).not.toContain('W_UNKNOWN_OUTPUT_PATH') }) + + it('lists only the outputs readable from outside a container when an unknown one has no near name', () => { + const text = source( + "const l = loop.forEach('L', { collection: [] }, (p) => {})\nconst b = api('B', { url: l.value })" + ) + expectDiagnostic( + run(text), + 'W_UNKNOWN_OUTPUT_PATH', + locate(text, 'l.value'), + 'A loop has: results, result.' + ) + }) }) describe('errors, each with its code, location and hint', () => { @@ -725,6 +737,13 @@ describe('errors, each with its code, location and hint', () => { 'p.curentItem', 'Did you mean p.currentItem?', ], + [ + 'an unknown loop property with no near name', + "const l = loop.forEach('L', { collection: [] }, (p) => {\n const a = api('A', { url: p.value })\n p.to(a)\n})", + 'E_UNKNOWN_SUBFLOW_PROPERTY', + 'p.value', + 'A loop has: p.index, p.currentItem, p.items, p.iteration, p.item.', + ], [ 'subflow data on a block that is not a container', "const s = slack.sendMessage('S', { authMethod: 'oauth', text: 'x' }, { subflowData: { count: 2 } })", diff --git a/packages/workflow-code/src/compile/values.ts b/packages/workflow-code/src/compile/values.ts index fa6594bb451..4aa6b02e229 100644 --- a/packages/workflow-code/src/compile/values.ts +++ b/packages/workflow-code/src/compile/values.ts @@ -133,7 +133,7 @@ export const SDK_VALUE_FUNCTIONS: ReadonlySet = new Set([ 'vars', ] as const satisfies readonly SdkCoreExport[]) -/** Named-form container outputs (`LoopResolver` / `ParallelResolver` `KNOWN_PROPERTIES`). */ +/** Named-form container outputs (`LoopResolver` / `ParallelResolver` `OUTPUT_PROPERTIES`). */ const CONTAINER_OUTPUTS = ['results', 'result'] function rejectNode(ctx: CompileContext, node: Node, site?: ValueSite): null { @@ -818,7 +818,18 @@ function checkOutputPath( 'W_UNKNOWN_OUTPUT_PATH', `A ${containerKind} has no output ${first.name}.`, at, - { hint: () => didYouMean(first.name, known), blockKey } + { + hint: () => { + const readable = known.filter( + (name) => + !readsIterationOutOfScope(blockKey, target, name, (key) => scopeNodeOf(ctx, key)) + ) + return ( + didYouMean(first.name, readable) ?? `A ${containerKind} has: ${readable.join(', ')}.` + ) + }, + blockKey, + } ) } if (first.kind === 'name') checkIterationScope(ctx, at, blockKey, target, first.name) @@ -1128,7 +1139,9 @@ function subflowScopeRef( `A ${kind} has no property ${property ?? '(none)'}.`, rangeOf(ctx, node), { - hint: didYouMean(property ?? '', known, (name) => `${label}.${name}`), + hint: + didYouMean(property ?? '', known, (name) => `${label}.${name}`) ?? + `A ${kind} has: ${known.map((name) => `${label}.${name}`).join(', ')}.`, blockKey: site.decl.key, } )