fix(http-server-js): createPolicyChain returns a Promise when policies are present#9917
Draft
fix(http-server-js): createPolicyChain returns a Promise when policies are present#9917
Conversation
…specified Co-authored-by: markcowl <1054056+markcowl@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix error when adding a global policy in http-server-js
fix(http-server-js): createPolicyChain returns Promise when policies are present
Mar 4, 2026
…ilot/fix-global-policy-error
Co-authored-by: markcowl <1054056+markcowl@users.noreply.github.com>
Copilot
AI
changed the title
fix(http-server-js): createPolicyChain returns Promise when policies are present
fix(http-server-js): createPolicyChain returns a Promise when policies are present
Mar 9, 2026
benjlevesque
reviewed
Mar 9, 2026
| * @param policies - The policies to apply to the request. | ||
| * @param out - The function to call after the policies have been applied. | ||
| */ | ||
| export function createPolicyChain<Out extends (ctx: HttpContext, ...rest: any[]) => void>( |
There was a problem hiding this comment.
Considering the result function of createPolicyChain is always awaited, I feel Out should always return a promise, so that the result is necessarily a promise, whether there's a policy or not
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Using global policies with the generated router caused
TypeError: Cannot read properties of undefined (reading 'catch')becausecreatePolicyChainreturned a function that returnedundefinedinstead of aPromise. The generated router calls.catch()on the dispatch result, which fails when no Promise is returned.Changes
src/helpers/router.ts: MadeapplyPolicyreturnPromise<void>. The base case wrapsout(...)inPromise.resolve(). The recursive case usesnew Promisewith try/catch to handle synchronous policy errors, chaining downstream via.then(resolve, reject). The returned wrapper function now propagates the Promise.generated-defs/helpers/router.ts: Regenerated to reflect the source change.test/router.test.ts: Added unit tests covering Promise return, policy execution order, error propagation fromout, synchronous policy throws, and request forwarding.Warning
Firewall rules blocked me from connecting to one or more addresses (expand for details)
I tried to connect to the following addresses, but was blocked by firewall rules:
telemetry.astro.build/home/REDACTED/work/_temp/ghcca-node/node/bin/node node /home/REDACTED/work/typespec/typespec/website/node_modules/.bin/../astro/astro.js build node pec/�� tput-dir ../../w--llmstxt sh _modules/.bin/no../../website/src/content/docs/docs/emitters/openapi3/reference --no-emit ture dist/node-gyp-bigenerate-scenarios-summary sed tobu�� s,\\,/,g sh /node_modules/.bin/sh import @typespecnode ture tobuf/reference node(dns block)If you need me to access, download, or install something from one of these locations, you can either:
Original prompt
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.