Skip to content

Commit 02943ea

Browse files
committed
fix(@angular-devkit/architect): properly subscribe to error handlers
If an error is reported but ANY subscription have an undefined error handler, RxJS reports the error to the "host platform" (it setTimeout(() => throw error)). Since we properly handle errors in some places, but should ignore them in others (e.g. we handle errors on the outboundBus, so the output subscription should ignore it), we still need to subscribe to error, just ignore it.
1 parent f0adbc4 commit 02943ea

File tree

1 file changed

+20
-11
lines changed

1 file changed

+20
-11
lines changed

packages/angular_devkit/architect/src/schedule-by-name.ts

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88
import { experimental, json, logging } from '@angular-devkit/core';
9-
import { Subscription } from 'rxjs';
10-
import { first, ignoreElements, map, shareReplay } from 'rxjs/operators';
9+
import { EMPTY, Subscription } from 'rxjs';
10+
import { catchError, first, ignoreElements, map, share, shareReplay, tap } from 'rxjs/operators';
1111
import {
1212
BuilderInfo,
1313
BuilderInput,
@@ -60,46 +60,55 @@ export async function scheduleByName(
6060
if (event.kind === experimental.jobs.JobOutboundMessageKind.Start) {
6161
job.input.next(message);
6262
}
63-
});
63+
}, () => {});
6464
} else {
6565
job.input.next(message);
6666
}
6767

6868
const logChannelSub = job.getChannel<logging.LogEntry>('log').subscribe(entry => {
6969
logger.next(entry);
70-
});
70+
}, () => {});
7171

72-
const s = job.outboundBus.subscribe(
73-
undefined,
74-
undefined,
75-
() => {
72+
const s = job.outboundBus.subscribe({
73+
error() {},
74+
complete() {
7675
s.unsubscribe();
7776
logChannelSub.unsubscribe();
7877
if (stateSubscription) {
7978
stateSubscription.unsubscribe();
8079
}
8180
},
82-
);
81+
});
8382
const output = job.output.pipe(
8483
map(output => ({
8584
...output,
8685
...options.target ? { target: options.target } : 0,
8786
info,
8887
} as BuilderOutput)),
88+
shareReplay(),
8989
);
9090

91+
// Start the builder.
92+
output.pipe(first()).subscribe({
93+
error() {},
94+
});
95+
9196
return {
9297
id,
9398
info,
94-
result: output.pipe(first()).toPromise(),
99+
// This is a getter so that it always returns the next output, and not the same one.
100+
get result() { return output.pipe(first()).toPromise(); },
95101
output,
96102
progress: job.getChannel<BuilderProgressReport>('progress', progressSchema).pipe(
97103
shareReplay(1),
98104
),
99105
stop() {
100106
job.stop();
101107

102-
return output.pipe(ignoreElements()).toPromise();
108+
return job.outboundBus.pipe(
109+
ignoreElements(),
110+
catchError(() => EMPTY),
111+
).toPromise();
103112
},
104113
};
105114
}

0 commit comments

Comments
 (0)