Skip to content

fix: avoid concealing build errors #5520

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 7 commits into from

Conversation

gtm-nayan
Copy link
Contributor

@gtm-nayan gtm-nayan commented Jul 14, 2022

closes #5413

Please don't delete this checklist! Before submitting the PR, please make sure you do the following:

  • It's really useful if your PR references an issue where it is discussed ahead of time. In many cases, features are absent for a reason. For large changes, please create an RFC: https://github.com/sveltejs/rfcs
  • This message body should clearly illustrate what problems it solves.
  • Ideally, include a test that fails without this PR but passes with it.

Tests

  • Run the tests with pnpm test and lint the project with pnpm lint and pnpm check

Changesets

  • If your PR makes a change that should be noted in one or more packages' changelogs, generate a changeset by running pnpm changeset and following the prompts. All changesets should be patch until SvelteKit 1.0

@changeset-bot
Copy link

changeset-bot bot commented Jul 14, 2022

🦋 Changeset detected

Latest commit: 681d785

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@sveltejs/kit Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@gtm-nayan
Copy link
Contributor Author

Not yet, https://discord.com/channels/457912077277855764/571775594002513921/997058576075997214

@gtm-nayan gtm-nayan marked this pull request as draft July 14, 2022 14:13
@Rich-Harris
Copy link
Member

This feels like quite a bit of complexity. IIRC the reason we're not doing the adapt step inside writeBundle is that calling process.exit(0) in that hook risks interfering with other plugins. What if we just followed through on #5306 — could we avoid all this?

@benmccann
Copy link
Member

I had wondered as well and #5306 would certainly be nice to fix given the number of issues it has caused, but I think the answer is that we still need this because what would it mean to run the adapter on a failed build? I talked with patak that we need additional hooks at the end of the Vite build, so I think that may be part of the answer long-term as well

@Rich-Harris
Copy link
Member

If adapting was part of writeBundle then it wouldn't run on a failed build. we wouldn't get that far into the function

@benmccann
Copy link
Member

Yes, but it would break Vite plugins that output anything during writeBundle as the adapter could no longer utilize their output

@Rich-Harris
Copy link
Member

Ah, I see. What does that mean in practice though? Are there any adapters that depend on the output of a Vite plugin? Even if so, it feels like all that would need to happen is that the SvelteKit plugin goes after any plugins that generate output the adapter depends on.

@benmccann
Copy link
Member

Ah, I see. What does that mean in practice though? Are there any adapters that depend on the output of a Vite plugin?

It's not really specific to any adapter. E.g. vite-plugin-pwa generates files during writeBundle, but they weren't making them from .svelte-kit to build or wherever until we moved the adapt phase to happen later

Even if so, it feels like all that would need to happen is that the SvelteKit plugin goes after any plugins that generate output the adapter depends on.

Unfortunately not because all writeBundle hooks run in parallel

Copy link
Member

@Rich-Harris Rich-Harris left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

given that we're not using the actual values of build_error or write_bundle_error anywhere, can we just track it as a boolean? suggestions inline

Comment on lines +112 to +116
/** @type {Error | undefined} */
let build_error;

/** @type {Error | undefined} */
let write_bundle_error;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/** @type {Error | undefined} */
let build_error;
/** @type {Error | undefined} */
let write_bundle_error;
let errored = false;

@@ -247,6 +253,9 @@ function kit() {
* Clears the output directories.
*/
buildStart() {
// Reset errors in watch mode
build_error = write_bundle_error = undefined;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
build_error = write_bundle_error = undefined;
errored = false;

@@ -256,6 +265,10 @@ function kit() {
}
},

buildEnd(err) {
build_error = err;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
build_error = err;
errored = !!err;


await build_service_worker(options, prerendered, client.vite_manifest);
} catch (error) {
throw (write_bundle_error = /** @type {Error} */ (error));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
throw (write_bundle_error = /** @type {Error} */ (error));
errored = true;
throw (error);

@@ -354,6 +373,11 @@ function kit() {
if (!is_build) {
return; // vite calls closeBundle when dev-server restarts, ignore that
}

if (build_error || write_bundle_error) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (build_error || write_bundle_error) {
if (errored) {

@Rich-Harris
Copy link
Member

in fact, could we make it even simpler than my suggestion above? rather than tracking failure, we could track success. presumably writeBundle isn't called if the build fails, so we could get rid of the buildEnd hook, and just set completed_build = true at the end of writeBundle. opening a PR against this branch, one sec

@Rich-Harris
Copy link
Member

#5536

Rich-Harris added a commit that referenced this pull request Jul 14, 2022
* loop over values instead with `Object.values`

* missed a closing bracket

* avoid concealing build errors

* fix comment

* changeset

* Handle errors in writeBundle

* inline comments

* track success rather than failure

* oops, missing piece

Co-authored-by: Ignatius Bagus <ignatius.mbs@gmail.com>
Co-authored-by: gtm-nayan <gtmnayan@gmail.com>
@Rich-Harris
Copy link
Member

closing since #5536 was merged — thanks all

@gtm-nayan gtm-nayan deleted the missing-imports branch July 16, 2022 06:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Improper import in route does not throw but builds nothing
5 participants