Skip to content

Commit

Permalink
don't emit error at environment, environment's queueTask to handle fa…
Browse files Browse the repository at this point in the history
…ilures.
  • Loading branch information
mshima committed Jun 12, 2023
1 parent a75dbf8 commit 02e6785
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 7 deletions.
8 changes: 1 addition & 7 deletions src/actions/lifecycle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -345,13 +345,7 @@ export abstract class TasksMixin {
return;
}

try {
this.env.emit('error', error);
} catch (error: unknown) {
setImmediate(() => {
throw error;
});
}
throw error;
} finally {
delete this.runningState;
}
Expand Down
35 changes: 35 additions & 0 deletions test/base.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { fileURLToPath, pathToFileURL } from 'node:url';
import { createRequire } from 'node:module';
import process from 'node:process';
import { Buffer } from 'node:buffer';
import { esmocha, expect } from 'esmocha';
import { extend } from 'lodash-es';
import { spy as sinonSpy, fake as sinonFake, assert as sinonAssert } from 'sinon';
import { passthrough } from '@yeoman/transform';
Expand Down Expand Up @@ -1461,6 +1462,40 @@ describe('Base', () => {
await gen.run();
assert.equal(thrown, true);
});

it('rejecting a task should stop the queue', async function () {
const gen = new Generator({
resolved: resolveddir,
namespace: 'dummy',
env,
testQueue: 'This value',
});

const queueName = 'configuring';
gen.queueTask({
method() {
throw new Error('Some error');
},
queueName,
taskName: 'foo',
run: false,
});

const secondTask = esmocha.fn();
gen.queueTask({
method: secondTask,
queueName,
taskName: 'secondTask',
run: false,
});

await expect(gen.run()).rejects.toThrow('Some error');
if (env.runLoop) {
expect(env.runLoop.running).toBe(false);
}

expect(secondTask).not.toHaveBeenCalled();
});
});

describe('Custom priorities', () => {
Expand Down

0 comments on commit 02e6785

Please sign in to comment.