diagnostics_channel: ensure tracePromise consistency with non-Promises#61766
diagnostics_channel: ensure tracePromise consistency with non-Promises#61766Renegade334 wants to merge 1 commit intonodejs:mainfrom
Conversation
| // TODO: Is there a way to have asyncEnd _after_ the continuation? | ||
| asyncEnd.publish(context); | ||
| return PromiseReject(err); | ||
| throw err; |
There was a problem hiding this comment.
Throwing here avoids Promisifying thenables on rejection. The Promises/A+ standard dictates that throwing within the promise handlers results in the returned thenable rejecting. (https://promisesaplus.com/#point-42)
For native Promises, there should be no observable change.
There was a problem hiding this comment.
Is there already an existing testcase for this?
if not maybe a good idea to add one.
There was a problem hiding this comment.
It's covered by
b54c7f4 to
71a5eb2
Compare
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #61766 +/- ##
==========================================
- Coverage 89.72% 89.71% -0.01%
==========================================
Files 675 675
Lines 204797 204805 +8
Branches 39344 39346 +2
==========================================
- Hits 183752 183744 -8
- Misses 13324 13334 +10
- Partials 7721 7727 +6
🚀 New features to boost your workflow:
|
71a5eb2 to
6b6f40a
Compare
6b6f40a to
1c9c33b
Compare
|
@nodejs/diagnostics any eyes welcome. |
This comment has been minimized.
This comment has been minimized.
| // TODO: Is there a way to have asyncEnd _after_ the continuation? | ||
| asyncEnd.publish(context); | ||
| return PromiseReject(err); | ||
| throw err; |
There was a problem hiding this comment.
Is there already an existing testcase for this?
if not maybe a good idea to add one.
tracingChannel.tracePromise()is documented in the source code (albeit not in the docs) to accept functions that return non-Promise thenables. However, it currently has some wonky behaviour when the return value isn't a native Promise, and also in the undocumented case where the return value isn't promise-like at all.What gets returned by
tracePromise()is highly dependent on whether the tracing channel has active subscribers or not:resulttyperesultresult.then(...)resultPromise.resolve(result).then(...)resultPromise.resolve(result).then(...)The major inconsistencies are:
asyncStart/asyncEndevents, despite no asynchronous execution. On the other hand, if the wrapped function throws synchronously, these events are not produced.This PR makes some changes to the non-Promise cases to make the behaviours consistent.
result.then(...)(if active subscribers).asyncStartorasyncEndevents are produced.resulttyperesultresult.then(...)resultresult.then(...)resultresultFixes: #59936