Improve TypeScript AppHost missing-await errors#15106
Improve TypeScript AppHost missing-await errors#15106sebastienros merged 2 commits intorelease/13.2from
Conversation
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
🚀 Dogfood this PR with:
curl -fsSL https://raw.githubusercontent.com/dotnet/aspire/main/eng/scripts/get-aspire-cli-pr.sh | bash -s -- 15106Or
iex "& { $(irm https://raw.githubusercontent.com/dotnet/aspire/main/eng/scripts/get-aspire-cli-pr.ps1) } 15106" |
There was a problem hiding this comment.
Pull request overview
This PR improves the TypeScript AppHost developer experience by detecting unresolved Promise-like arguments before they cross JSON-RPC, then surfacing the problem as a user-facing “AppHost Error” with a missing-await hint (fixing the confusing internal capability/deserialization failure in #14724).
Changes:
- Added Promise-like argument validation in the generated TypeScript transport and introduced
AppHostUsageErrorfor clearer user errors. - Updated generated SDK error handling to format
AppHostUsageErroras❌ AppHost Error:in global rejection/exception handlers. - Replaced the transport snapshot-only coverage with an end-to-end CLI test that creates a TS AppHost missing an
awaitand asserts the helpful error output.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
src/Aspire.Hosting.CodeGeneration.TypeScript/Resources/transport.ts |
Adds AppHostUsageError and validates capability args for Promise-like values before JSON-RPC invocation. |
src/Aspire.Hosting.CodeGeneration.TypeScript/AtsTypeScriptCodeGenerator.cs |
Updates generated imports/exports and global error handling to recognize and format AppHostUsageError. |
tests/Aspire.Cli.EndToEnd.Tests/TypeScriptCodegenValidationTests.cs |
Adds an end-to-end regression test that verifies the new missing-await hint. |
tests/Aspire.Hosting.CodeGeneration.TypeScript.Tests/Snapshots/AtsGeneratedAspire.verified.ts |
Snapshot update to re-export AppHostUsageError and adjust error handling output. |
tests/Aspire.Hosting.CodeGeneration.TypeScript.Tests/Snapshots/TwoPassScanningGeneratedAspire.verified.ts |
Snapshot update to re-export AppHostUsageError and adjust error handling output. |
tests/Aspire.Hosting.CodeGeneration.TypeScript.Tests/Snapshots/transport.verified.ts |
Removes the transport snapshot (coverage moved to higher-level test). |
| for (const [key, nestedValue] of Object.entries(value)) { | ||
| validateValue(nestedValue, `${path}.${key}`); | ||
| } |
There was a problem hiding this comment.
validateCapabilityArgs currently recurses into any object via Object.entries(value). Some SDK types (e.g., ReferenceExpression / ResourceBuilderBase) are class instances that carry a _client reference and implement toJSON() for transport serialization; traversing them can walk into the AspireClient / socket object graph and add avoidable overhead on every capability call. Consider limiting recursion to plain JSON objects/arrays and treating non-plain objects (or objects with a toJSON() function) as atomic, or validating the result of toJSON() instead of enumerating instance fields.
tests/Aspire.Cli.EndToEnd.Tests/TypeScriptCodegenValidationTests.cs
Outdated
Show resolved
Hide resolved
🎬 CLI E2E Test RecordingsThe following terminal recordings are available for commit
📹 Recordings uploaded automatically from CI run #22917251503 |
…ts.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Description
Improves the TypeScript AppHost experience when an async builder call is missing
await.This change adds Promise-like argument validation in the generated TypeScript transport so unresolved builder/resource promises are rejected before they cross JSON-RPC, and surfaces them as a user-facing
AppHost Errorwith a helpful missing-awaithint instead of a confusing internal capability/deserialization failure.It also replaces the extra transport snapshot-only test with higher-level polyglot SDK coverage in
TypeScriptCodegenValidationTests, which creates a TypeScript AppHost script with a missingawaitand verifies the resulting error message.Validation:
./dotnet.sh test tests/Aspire.Hosting.CodeGeneration.TypeScript.Tests/Aspire.Hosting.CodeGeneration.TypeScript.Tests.csproj -- --filter-not-trait "quarantined=true" --filter-not-trait "outerloop=true"./dotnet.sh build tests/Aspire.Cli.EndToEnd.Tests/Aspire.Cli.EndToEnd.Tests.csproj./build.sh --build /p:SkipNativeBuild=trueFixes #14724
Checklist
<remarks />and<code />elements on your triple slash comments?aspire.devissue: