Skip to content

Commit

Permalink
Merge pull request #10013 from kellyselden/handle-build-failures
Browse files Browse the repository at this point in the history
[BUGFIX] Handle rebuild failures without exiting
  • Loading branch information
kellyselden committed Oct 4, 2022
2 parents 1376857 + 241e1a8 commit a9e3e2c
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
4 changes: 4 additions & 0 deletions lib/models/builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,10 @@ class Builder extends CoreObject {
} catch (error) {
await this.processAddonBuildSteps('buildError', error);

// Mark this as a builder error so the watcher knows it has been handled
// and won't re-throw it
error.isBuilderError = true;

throw error;
} finally {
clearInterval(uiProgressIntervalID);
Expand Down
11 changes: 10 additions & 1 deletion lib/tasks/server/middleware/history-support/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,16 @@ class HistorySupportAddon {

app.use(async (req, _, next) => {
try {
const results = await watcher;
let results;
try {
results = await watcher;
} catch (e) {
// This means there was a build error, so we won't actually be serving
// index.html, and we have nothing to do. We have to catch it here,
// though, or it will go uncaught and cause the process to exit.
return;
}

if (this.shouldHandleRequest(req, options)) {
let assetPath = req.path.slice(baseURL.length);
let isFile = false;
Expand Down
14 changes: 14 additions & 0 deletions tests/unit/models/builder-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,20 @@ describe('models/builder.js', function () {
await expect(builder.build()).to.be.rejected;
expect(hooksCalled).to.deep.equal(['preBuild', 'build', 'postBuild', 'outputReady', 'buildError']);
});

it('sets `isBuilderError` on handled addon errors', async function () {
addon.postBuild = function () {
return Promise.reject(new Error('preBuild Error'));
};

let error;
try {
await builder.build();
} catch (e) {
error = e;
}
expect(error).to.haveOwnProperty('isBuilderError', true);
});
});

describe('fallback from broccoli 2 to broccoli-builder', function () {
Expand Down

0 comments on commit a9e3e2c

Please sign in to comment.