mirror of
https://github.com/angular/angular-cli.git
synced 2025-05-15 18:13:38 +08:00
fix(@angular-devkit/architect): properly report errors thrown by builder
When they are thrown by the builder itself.
This commit is contained in:
parent
e6ba05ba64
commit
f0adbc41fd
@ -6,7 +6,7 @@
|
||||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
import { experimental, isPromise, json, logging } from '@angular-devkit/core';
|
||||
import { Observable, Subscription, from, isObservable, of } from 'rxjs';
|
||||
import { Observable, Subscription, from, isObservable, of, throwError } from 'rxjs';
|
||||
import { tap } from 'rxjs/operators';
|
||||
import {
|
||||
BuilderContext,
|
||||
@ -14,6 +14,7 @@ import {
|
||||
BuilderInfo,
|
||||
BuilderInput,
|
||||
BuilderOutput,
|
||||
BuilderOutputLike,
|
||||
BuilderProgressState,
|
||||
Target,
|
||||
TypedBuilderProgress,
|
||||
@ -148,7 +149,12 @@ export function createBuilder<
|
||||
};
|
||||
|
||||
context.reportRunning();
|
||||
let result = fn(i.options as OptT, context);
|
||||
let result: BuilderOutputLike;
|
||||
try {
|
||||
result = fn(i.options as OptT, context);
|
||||
} catch (e) {
|
||||
result = throwError(e);
|
||||
}
|
||||
|
||||
if (isPromise(result)) {
|
||||
result = from(result);
|
||||
|
@ -9,7 +9,7 @@ import { schema } from '@angular-devkit/core';
|
||||
import { timer } from 'rxjs';
|
||||
import { map, take, tap, toArray } from 'rxjs/operators';
|
||||
import { TestingArchitectHost } from '../testing/testing-architect-host';
|
||||
import { BuilderOutput } from './api';
|
||||
import { BuilderOutput, BuilderRun } from './api';
|
||||
import { Architect } from './architect';
|
||||
import { createBuilder } from './create-builder';
|
||||
|
||||
@ -135,4 +135,54 @@ describe('architect', () => {
|
||||
expect(results).toBe(10);
|
||||
expect(all.length).toBe(10);
|
||||
});
|
||||
|
||||
it('reports errors in the builder', async () => {
|
||||
testArchitectHost.addBuilder('package:error', createBuilder(() => {
|
||||
throw new Error('Error in the builder.');
|
||||
}));
|
||||
|
||||
let run: BuilderRun | undefined = undefined;
|
||||
try {
|
||||
try {
|
||||
// This should not throw.
|
||||
run = await architect.scheduleBuilder('package:error', {});
|
||||
} catch (err) {
|
||||
expect(err).toBeUndefined();
|
||||
throw err;
|
||||
}
|
||||
|
||||
// This should throw.
|
||||
await run.result;
|
||||
expect('to throw').not.toEqual('to throw');
|
||||
} catch {
|
||||
}
|
||||
if (run) {
|
||||
await run.stop();
|
||||
}
|
||||
});
|
||||
|
||||
it('reports errors in the builder (async)', async () => {
|
||||
testArchitectHost.addBuilder('package:error', createBuilder(() => {
|
||||
return new Promise((_, reject) => reject(new Error('Error async')));
|
||||
}));
|
||||
|
||||
let run: BuilderRun | undefined = undefined;
|
||||
try {
|
||||
try {
|
||||
// This should not throw.
|
||||
run = await architect.scheduleBuilder('package:error', {});
|
||||
} catch (err) {
|
||||
expect(err).toBeUndefined();
|
||||
throw err;
|
||||
}
|
||||
|
||||
// This should throw.
|
||||
await run.result;
|
||||
expect('to throw').not.toEqual('to throw');
|
||||
} catch {
|
||||
}
|
||||
if (run) {
|
||||
await run.stop();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user