From 61c3bf0ad134d40e3219c6bb5421dc49147a0ca0 Mon Sep 17 00:00:00 2001 From: ishabi Date: Fri, 27 Nov 2026 22:08:28 +0100 Subject: [PATCH 1/2] diagnostics_channel: skip empty DisposableStack Signed-off-by: ishabi --- lib/diagnostics_channel.js | 39 ++++++++++++++++++++------------------ 1 file changed, 21 insertions(+), 18 deletions(-) diff --git a/lib/diagnostics_channel.js b/lib/diagnostics_channel.js index 61d310d383a9..70b97abe2bef 100644 --- a/lib/diagnostics_channel.js +++ b/lib/diagnostics_channel.js @@ -100,28 +100,31 @@ class RunStoresScope { #stack; constructor(activeChannel, data) { + if (!activeChannel._stores?.size) { + activeChannel.publish(data); + return; + } + using stack = new DisposableStack(); // Enter stores using withScope - if (activeChannel._stores) { - for (const entry of activeChannel._stores.entries()) { - const store = entry[0]; - const transform = entry[1]; - - let newContext = data; - if (transform) { - try { - newContext = transform(data); - } catch (err) { - process.nextTick(() => { - triggerUncaughtException(err, false); - }); - continue; - } + for (const entry of activeChannel._stores.entries()) { + const store = entry[0]; + const transform = entry[1]; + + let newContext = data; + if (transform) { + try { + newContext = transform(data); + } catch (err) { + process.nextTick(() => { + triggerUncaughtException(err, false); + }); + continue; } - - DisposableStackPrototypeUse(stack, store.withScope(newContext)); } + + DisposableStackPrototypeUse(stack, store.withScope(newContext)); } // Publish data @@ -132,7 +135,7 @@ class RunStoresScope { } [SymbolDispose]() { - this.#stack[SymbolDispose](); + this.#stack?.[SymbolDispose](); } } From b28a4bebba8decd2850352d220157aac04906c3d Mon Sep 17 00:00:00 2001 From: ishabi Date: Wed, 2 Dec 2026 14:37:00 +0100 Subject: [PATCH 2/2] use else block --- lib/diagnostics_channel.js | 55 +++++++++++++++++++------------------- 1 file changed, 27 insertions(+), 28 deletions(-) diff --git a/lib/diagnostics_channel.js b/lib/diagnostics_channel.js index 70b97abe2bef..2d37336e373a 100644 --- a/lib/diagnostics_channel.js +++ b/lib/diagnostics_channel.js @@ -100,38 +100,37 @@ class RunStoresScope { #stack; constructor(activeChannel, data) { - if (!activeChannel._stores?.size) { - activeChannel.publish(data); - return; - } - - using stack = new DisposableStack(); - - // Enter stores using withScope - for (const entry of activeChannel._stores.entries()) { - const store = entry[0]; - const transform = entry[1]; - - let newContext = data; - if (transform) { - try { - newContext = transform(data); - } catch (err) { - process.nextTick(() => { - triggerUncaughtException(err, false); - }); - continue; + if (activeChannel._stores?.size) { + using stack = new DisposableStack(); + + // Enter stores using withScope + for (const entry of activeChannel._stores.entries()) { + const store = entry[0]; + const transform = entry[1]; + + let newContext = data; + if (transform) { + try { + newContext = transform(data); + } catch (err) { + process.nextTick(() => { + triggerUncaughtException(err, false); + }); + continue; + } } - } - DisposableStackPrototypeUse(stack, store.withScope(newContext)); - } + DisposableStackPrototypeUse(stack, store.withScope(newContext)); + } - // Publish data - activeChannel.publish(data); + // Publish data + activeChannel.publish(data); - // Transfer ownership of the stack - this.#stack = DisposableStackPrototypeMove(stack); + // Transfer ownership of the stack + this.#stack = DisposableStackPrototypeMove(stack); + } else { + activeChannel.publish(data); + } } [SymbolDispose]() {