From 7a679a3faa381c6a930b08b73b1d4080ad554533 Mon Sep 17 00:00:00 2001 From: Austin Eng Date: Thu, 15 Dec 2022 21:15:40 -0800 Subject: [PATCH] Prefix subcase recorder error stacks with the subcase name (#2086) The deferred nature of subcases makes it hard to tell which failures came from which subcases. Prefix all error messages from subcases with their subcase name. --- src/common/internal/test_group.ts | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/common/internal/test_group.ts b/src/common/internal/test_group.ts index d2846dc602ed..2ad7a7468036 100644 --- a/src/common/internal/test_group.ts +++ b/src/common/internal/test_group.ts @@ -525,6 +525,7 @@ class RunCaseSpecific implements RunCase { // Make a recorder that will defer all calls until `allPreviousSubcasesFinalizedPromise` // resolves. Waiting on `allPreviousSubcasesFinalizedPromise` ensures that // logs from all the previous subcases have been flushed before flushing new logs. + const subcasePrefix = 'subcase: ' + stringifyPublicParams(subParams); const subRec = new Proxy(rec, { get: (target, k: keyof TestCaseRecorder) => { const prop = TestCaseRecorder.prototype[k]; @@ -532,6 +533,13 @@ class RunCaseSpecific implements RunCase { testHeartbeatCallback(); return function (...args: Parameters) { void allPreviousSubcasesFinalizedPromise.then(() => { + // Prepend the subcase name to all error messages. + for (const arg of args) { + if (arg instanceof Error) { + arg.message = subcasePrefix + '\n' + arg.message; + } + } + // eslint-disable-next-line @typescript-eslint/no-explicit-any const rv = (prop as any).apply(target, args); // Because this proxy executes functions in a deferred manner, @@ -544,8 +552,6 @@ class RunCaseSpecific implements RunCase { }, }); - subRec.info(new Error('subcase: ' + stringifyPublicParams(subParams))); - const params = mergeParams(this.params, subParams); const subcaseQuery = new TestQuerySingleCase( selfQuery.suite, @@ -573,6 +579,9 @@ class RunCaseSpecific implements RunCase { /* throwSkip */ true, getExpectedStatus(subcaseQuery) ) + .then(() => { + subRec.info(new Error('OK')); + }) .catch(ex => { if (ex instanceof SkipTestCase) { // Convert SkipTestCase to info messages