mirror of
https://github.com/angular/angular-cli.git
synced 2025-05-16 18:43:42 +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
|
* found in the LICENSE file at https://angular.io/license
|
||||||
*/
|
*/
|
||||||
import { experimental, isPromise, json, logging } from '@angular-devkit/core';
|
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 { tap } from 'rxjs/operators';
|
||||||
import {
|
import {
|
||||||
BuilderContext,
|
BuilderContext,
|
||||||
@ -14,6 +14,7 @@ import {
|
|||||||
BuilderInfo,
|
BuilderInfo,
|
||||||
BuilderInput,
|
BuilderInput,
|
||||||
BuilderOutput,
|
BuilderOutput,
|
||||||
|
BuilderOutputLike,
|
||||||
BuilderProgressState,
|
BuilderProgressState,
|
||||||
Target,
|
Target,
|
||||||
TypedBuilderProgress,
|
TypedBuilderProgress,
|
||||||
@ -148,7 +149,12 @@ export function createBuilder<
|
|||||||
};
|
};
|
||||||
|
|
||||||
context.reportRunning();
|
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)) {
|
if (isPromise(result)) {
|
||||||
result = from(result);
|
result = from(result);
|
||||||
|
@ -9,7 +9,7 @@ import { schema } from '@angular-devkit/core';
|
|||||||
import { timer } from 'rxjs';
|
import { timer } from 'rxjs';
|
||||||
import { map, take, tap, toArray } from 'rxjs/operators';
|
import { map, take, tap, toArray } from 'rxjs/operators';
|
||||||
import { TestingArchitectHost } from '../testing/testing-architect-host';
|
import { TestingArchitectHost } from '../testing/testing-architect-host';
|
||||||
import { BuilderOutput } from './api';
|
import { BuilderOutput, BuilderRun } from './api';
|
||||||
import { Architect } from './architect';
|
import { Architect } from './architect';
|
||||||
import { createBuilder } from './create-builder';
|
import { createBuilder } from './create-builder';
|
||||||
|
|
||||||
@ -135,4 +135,54 @@ describe('architect', () => {
|
|||||||
expect(results).toBe(10);
|
expect(results).toBe(10);
|
||||||
expect(all.length).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