Skip to content

Commit 70dabe7

Browse files
fixup! diagnostics_channel: replace using with try-finally
Signed-off-by: Ayush Chaudhary <ayush23chaudhary@gmail.com>
1 parent 38c0c64 commit 70dabe7

1 file changed

Lines changed: 21 additions & 5 deletions

File tree

‎lib/diagnostics_channel.js‎

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ const {
2020
} = primordials;
2121

2222
const {
23+
aggregateTwoErrors,
2324
codes: {
2425
ERR_INVALID_ARG_TYPE,
2526
},
@@ -84,6 +85,19 @@ function maybeMarkInactive(channel) {
8485
}
8586
}
8687

88+
function disposeStoreScopes(stack, error, hasError = false) {
89+
for (let i = stack.length - 1; i >= 0; i--) {
90+
try {
91+
stack[i][SymbolDispose]();
92+
} catch (err) {
93+
error = hasError ? aggregateTwoErrors(err, error) : err;
94+
hasError = true;
95+
}
96+
}
97+
98+
if (hasError) throw error;
99+
}
100+
87101
class RunStoresScope {
88102
#stack;
89103

@@ -109,7 +123,11 @@ class RunStoresScope {
109123
}
110124
}
111125

112-
ArrayPrototypePush(stack, store.withScope(newContext));
126+
try {
127+
ArrayPrototypePush(stack, store.withScope(newContext));
128+
} catch (err) {
129+
disposeStoreScopes(stack, err, true);
130+
}
113131
}
114132
}
115133

@@ -126,9 +144,7 @@ class RunStoresScope {
126144
const stack = this.#stack;
127145
this.#stack = undefined;
128146

129-
for (let i = stack.length - 1; i >= 0; i--) {
130-
stack[i][SymbolDispose]();
131-
}
147+
disposeStoreScopes(stack);
132148
}
133149
}
134150
}
@@ -673,4 +689,4 @@ module.exports = {
673689
boundedChannel,
674690
Channel,
675691
BoundedChannel,
676-
};
692+
};

0 commit comments

Comments
 (0)