Skip to content

Commit 5780d93

Browse files
committed
fix(server): walk into Cause Fail reasons when detecting nested interrupt causes
findInterruptCause previously returned undefined immediately upon encountering any Cause that was not interrupt-only, without inspecting the Fail reasons' error values. This meant a Cause like Cause.fail(new Error('cancelled', { cause: Cause.interrupt() })) would not be recognized as an interrupt, causing failEnvironmentInternal to log a synthetic 500 error and fail with EnvironmentHttpInternalError instead of re-propagating the interruption. Extract the loop body into a recursive walkForInterrupt helper that, upon hitting a non-interrupt-only Cause, iterates Fail reasons and continues walking each error's .cause chain. The depth budget and seen-set are shared across recursive calls to prevent unbounded traversal.
1 parent 307df64 commit 5780d93

1 file changed

Lines changed: 19 additions & 2 deletions

File tree

apps/server/src/auth/http.ts

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,27 @@ function failureLogAttributes(input: unknown) {
8383

8484
function findInterruptCause(input: unknown): Cause.Cause<never> | undefined {
8585
const seen = new Set<object>();
86+
return walkForInterrupt(input, seen, 0);
87+
}
88+
89+
function walkForInterrupt(
90+
input: unknown,
91+
seen: Set<object>,
92+
depth: number,
93+
): Cause.Cause<never> | undefined {
8694
let current = input;
87-
for (let depth = 0; depth < MAX_CAUSE_CHAIN_DEPTH; depth += 1) {
95+
for (let d = depth; d < MAX_CAUSE_CHAIN_DEPTH; d += 1) {
8896
if (Cause.isCause(current)) {
89-
return Cause.hasInterruptsOnly(current) ? (current as Cause.Cause<never>) : undefined;
97+
if (Cause.hasInterruptsOnly(current)) {
98+
return current as Cause.Cause<never>;
99+
}
100+
for (const reason of current.reasons) {
101+
if (Cause.isFailReason(reason)) {
102+
const found = walkForInterrupt(reason.error, seen, d + 1);
103+
if (found !== undefined) return found;
104+
}
105+
}
106+
return undefined;
90107
}
91108
if (typeof current !== "object" || current === null || seen.has(current)) {
92109
return undefined;

0 commit comments

Comments
 (0)