Skip to content

Commit 8c4df68

Browse files
committed
Build/Test Tools: Report nested publisher failures
The publisher collapsed multiple failures into an AggregateError and discarded every cause. That leaves a broken comment or label path with no actionable log.\n\nPrint the nested causes after the transaction has already failed. Publication behavior and exit status stay unchanged.
1 parent 7670d3b commit 8c4df68

2 files changed

Lines changed: 37 additions & 1 deletion

File tree

‎.github/scripts/docs-playground-preview/publish.mjs‎

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,20 @@ import { findPreviousPreview, loadPublishedPreview } from './lib/published.mjs';
1919

2020
class SupersededRun extends Error {}
2121

22+
export function formatFailure( error ) {
23+
const description = error.stack || String( error );
24+
if ( ! ( error instanceof AggregateError ) ) {
25+
return description;
26+
}
27+
return [
28+
description,
29+
...error.errors.map(
30+
( cause, index ) =>
31+
`Cause ${ index + 1 }:\n${ formatFailure( cause ) }`
32+
),
33+
].join( '\n' );
34+
}
35+
2236
async function readHandoff( directory ) {
2337
return JSON.parse(
2438
await readFile( path.join( directory, 'build.json' ), 'utf8' )
@@ -395,7 +409,7 @@ async function main() {
395409

396410
if ( import.meta.url === pathToFileURL( process.argv[ 1 ] ).href ) {
397411
main().catch( ( error ) => {
398-
process.stderr.write( `${ error.stack || error }\n` );
412+
process.stderr.write( `${ formatFailure( error ) }\n` );
399413
process.exitCode = 1;
400414
} );
401415
}

‎.github/scripts/docs-playground-preview/test/publish.test.mjs‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import {
1818
} from '../lib/publication.mjs';
1919
import {
2020
enforceValidationResult,
21+
formatFailure,
2122
publishPullRequest,
2223
} from '../publish.mjs';
2324

@@ -318,6 +319,27 @@ test( 'the trusted publisher enforces invalid fork handoffs', () => {
318319
);
319320
} );
320321

322+
test( 'publisher failures retain every nested cause in the Actions log', () => {
323+
const failure = new AggregateError(
324+
[
325+
new Error( 'candidate upload failed' ),
326+
new AggregateError(
327+
[
328+
new Error( 'comment failed' ),
329+
new Error( 'label removal failed' ),
330+
],
331+
'failure reporting failed'
332+
),
333+
],
334+
'publication failed'
335+
);
336+
const formatted = formatFailure( failure );
337+
338+
assert.match( formatted, /candidate upload failed/ );
339+
assert.match( formatted, /comment failed/ );
340+
assert.match( formatted, /label removal failed/ );
341+
} );
342+
321343
test( 'a missing handoff always fails after its terminal comment', async () => {
322344
const api = new FakeApi();
323345
const directory = await mkdtemp(

0 commit comments

Comments
 (0)