Skip to content

Commit 0c78c32

Browse files
crisbetojelbourn
authored andcommitted
build: server-side rendering check not failing for async errors (#17745)
If an error is thrown asynchronously during server-side rendering (e.g. in rxjs subscription or a `setTimeout`), it'll be logged to the console but the script will still exit with 0. These changes add an `ErrorHandler` that'll rethrow the errors so that the CI fails properly.
1 parent 15a5171 commit 0c78c32

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

src/universal-app/kitchen-sink-mdc/kitchen-sink-mdc.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {Component, NgModule} from '@angular/core';
1+
import {Component, NgModule, ErrorHandler} from '@angular/core';
22
import {MatButtonModule} from '@angular/material-experimental/mdc-button';
33
import {MatCardModule} from '@angular/material-experimental/mdc-card';
44
import {MatCheckboxModule} from '@angular/material-experimental/mdc-checkbox';
@@ -34,6 +34,17 @@ export class KitchenSinkMdc {
3434
],
3535
declarations: [KitchenSinkMdc],
3636
exports: [KitchenSinkMdc],
37+
providers: [{
38+
// If an error is thrown asynchronously during server-side rendering it'll get logged to stderr,
39+
// but it won't cause the build to fail. We still want to catch these errors so we provide an
40+
// `ErrorHandler` that re-throws the error and causes the process to exit correctly.
41+
provide: ErrorHandler,
42+
useValue: {handleError: ERROR_HANDLER}
43+
}]
3744
})
3845
export class KitchenSinkMdcModule {
3946
}
47+
48+
export function ERROR_HANDLER(error: Error) {
49+
throw error;
50+
}

src/universal-app/kitchen-sink/kitchen-sink.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import {FocusMonitor} from '@angular/cdk/a11y';
22
import {DragDropModule} from '@angular/cdk/drag-drop';
33
import {ScrollingModule, ViewportRuler} from '@angular/cdk/scrolling';
44
import {CdkTableModule, DataSource} from '@angular/cdk/table';
5-
import {Component, ElementRef, NgModule} from '@angular/core';
5+
import {Component, ElementRef, NgModule, ErrorHandler} from '@angular/core';
66
import {MatNativeDateModule, MatRippleModule} from '@angular/material/core';
77
import {MatAutocompleteModule} from '@angular/material/autocomplete';
88
import {MatButtonModule} from '@angular/material/button';
@@ -146,6 +146,17 @@ export class KitchenSink {
146146
declarations: [KitchenSink, TestEntryComponent],
147147
exports: [KitchenSink, TestEntryComponent],
148148
entryComponents: [TestEntryComponent],
149+
providers: [{
150+
// If an error is thrown asynchronously during server-side rendering it'll get logged to stderr,
151+
// but it won't cause the build to fail. We still want to catch these errors so we provide an
152+
// `ErrorHandler` that re-throws the error and causes the process to exit correctly.
153+
provide: ErrorHandler,
154+
useValue: {handleError: ERROR_HANDLER}
155+
}]
149156
})
150157
export class KitchenSinkModule {
151158
}
159+
160+
export function ERROR_HANDLER(error: Error) {
161+
throw error;
162+
}

0 commit comments

Comments
 (0)