Skip to content

[BUGFIX] Handle rebuild failures without exiting#9987

Merged
ef4 merged 2 commits intoember-cli:masterfrom
bendemboski:handle-build-failures
Aug 11, 2022
Merged

[BUGFIX] Handle rebuild failures without exiting#9987
ef4 merged 2 commits intoember-cli:masterfrom
bendemboski:handle-build-failures

Conversation

@bendemboski
Copy link
Copy Markdown
Contributor

@bendemboski bendemboski commented Aug 3, 2022

When a rebuild fails, mark it as a builder failure so the watcher doesn't re-throw it, causing it to be an unhandled error that results in the process exiting.

Fixes #9584 #9404

@bertdeblock bertdeblock requested a review from rwjblue August 9, 2022 17:59
@ef4
Copy link
Copy Markdown
Contributor

ef4 commented Aug 10, 2022

I confirmed that this does not fix either kind of crash.

(Meaning, an exception thrown out of template compilation or a rejected promise out of a postBuild hook.)

Remember to check that you can do a successful HTTP request after the build error. That is where the crash actually happens.

@bendemboski
Copy link
Copy Markdown
Contributor Author

bendemboski commented Aug 10, 2022

@ef4 I guess I haven't tested the template compilation scenario, but I am seeing it working for addons rejecting in the post-build hook. This doesn't address the case where that happens during the initial build, only during rebuilds -- I'm pretty sure initial build failures have "always" (i.e. as long as I can remember) caused the process to exit, so I wasn't aiming to address that. The main scenario I was targeting is that I introduce a typescript error while editing code and that causes ember-cli to exit, so even after I've fixed the typescript error I have to restart the whole process and do a full build.

here is an Ember app I threw together with instructions in the README to I believe demonstrates that this PR fixes the issue I'm describing.

@ef4
Copy link
Copy Markdown
Contributor

ef4 commented Aug 11, 2022

Thanks for sharing the repro app. For anybody else following along: make sure you run the repro on Node 15 or newer to see the crash.

Following the README, I can confirm that I observe the crash that you documented in the unmodified app. But then I followed the instructions to switch to this PR, and I can still make it crash. Here's the diff compared to the steps you wrote in the README:

To see that it fixes it:

1. In `package.json`, change the `ember-cli` version to git+ssh://git@github.com/bendemboski/ember-cli.git#handle-build-failures
2. `yarn`
3. `ember serve` (build succeeds)
2. Open http://localhost:4200 in a browser (UI loads)
3. Make a change to `application.hbs` (build fails, process does _not_ exit, browser does not reload)
-4. Make another change to `application.hbs` (build succeeds, browser reloads)
-5. Repeat steps 3-4 as desired
+4. Manually refresh localhost:4200 in the browser. (ember-cli crashes)

@ef4
Copy link
Copy Markdown
Contributor

ef4 commented Aug 11, 2022

Just to check that I'm not doing something dumb, here's the diff I get in yarn.lock when I switch to the PR:

diff --git a/yarn.lock b/yarn.lock
index 2c25036..8817fea 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -4658,10 +4658,9 @@ ember-cli-version-checker@^5.1.1, ember-cli-version-checker@^5.1.2:
     semver "^7.3.4"
     silent-error "^1.1.1"
 
-ember-cli@~4.6.0:
-  version "4.6.0"
-  resolved "https://registry.yarnpkg.com/ember-cli/-/ember-cli-4.6.0.tgz#ff409b99d074414a8944bdadf6db820eaf2dfb7b"
-  integrity sha512-4OAPHJJt4wARrTzfpfEM49KA1JJjMZ/8mhUncdqJFJG19/mS6yJiAUemnsLhZLnbjicB/gYSQ3rrUv/vxeX3cA==
+"ember-cli@git+ssh://git@github.com/bendemboski/ember-cli.git#handle-build-failures":
+  version "4.7.0-beta.0"
+  resolved "git+ssh://git@github.com/bendemboski/ember-cli.git#a8f619d108fd5ff2980f23a2664863f524b2844c"
   dependencies:
     "@babel/core" "^7.18.6"
     "@babel/plugin-transform-modules-amd" "^7.18.6"

@bendemboski
Copy link
Copy Markdown
Contributor Author

Okay, @ef4 I see what you're seeing now. There are two distinct issues, one where the process exits immediately upon an addon throwing from postBuild() (and likely other hooks), and another where the process exits when a request to serve the app is received when the most recent build failed.

My first commit fixed the first issue, and I just pushed a second commit that fixes the second issue. So now using my repro app,

  1. In package.json, change the ember-cli version to git+ssh://git@github.com/bendemboski/ember-cli.git#handle-build-failures
  2. yarn (might have to yarn --force to get the latest commit from my branch if the previous one is cached?)
  3. ember serve (build succeeds)
  4. Open http://localhost:4200 in a browser (UI loads)
  5. Make a change to application.hbs (build fails, process does not exit, browser does not reload)
  6. Manually refresh localhost:4200 in the browser. (process does not exit, browser loads build error page)
  7. Make another change to application.hbs (build succeeds, browser reloads)

Note that in step (4) the error page looks odd:

localhost_4200

I'm pretty sure this is a pre-existing issue where we aren't wrapping random errors thrown from addon hooks properly in the broccoli wrapper magic to make the error page look right -- it looks exactly as expected when the error is a template compilation error rather than my contrived addon hook error. I poked around a bit and couldn't easily figure out how best to address this, but IMO it should not hold up getting the core issues here fixed.

@ef4 ef4 enabled auto-merge August 11, 2022 03:09
When a rebuild fails, mark it as a builder failure so the watcher doesn't re-throw it, causing it to be an unhandled error that results in the process exiting.

Fixes ember-cli#9584
If the most recent build failed and an HTTP request came in, the history middleware would throw an uncaught exception causing the process to exit. Instead, catch and ignore.
@bertdeblock bertdeblock force-pushed the handle-build-failures branch from 6b3dc54 to 2e18a80 Compare August 11, 2022 06:59
@ef4 ef4 merged commit dfc71a9 into ember-cli:master Aug 11, 2022
@bertdeblock
Copy link
Copy Markdown
Member

Thanks @bendemboski and @ef4!

@jdaviderb
Copy link
Copy Markdown

When will this feature be released?

@MichalBryxi
Copy link
Copy Markdown

@jdaviderb from what I can see in the CHANGELOG the related issue was released in v4.8.0. But maybe I'm reading the history here wrong?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

v3.15 w/ Node 14+ crashes consistently when postBuild hook throws

5 participants