Skip to content

Commit

Permalink
fix(dev): do not log cancelation "errors"
Browse files Browse the repository at this point in the history
esbuild cancels builds by throwing cancelation errors,
and we copy the same approach for manually canceling builds

cancelations need to be thrown to stop execution, but they are not
in-themselves errors. so they should not be logged as errors.
  • Loading branch information
pcattori committed May 3, 2023
1 parent 52cd1e4 commit 8cad4ee
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 6 deletions.
7 changes: 7 additions & 0 deletions packages/remix-dev/compiler/cancel.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export const CANCEL_PREFIX = "remix-compile-cancel";

export class Cancel extends Error {
constructor(message: string) {
super(`${CANCEL_PREFIX}: ${message}`);
}
}
3 changes: 2 additions & 1 deletion packages/remix-dev/compiler/js/plugins/cssBundleUpdate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import type { Plugin } from "esbuild";
import { readFile } from "fs-extra";

import type * as Channel from "../../../channel";
import { Cancel } from "../../cancel";

const pluginName = "css-bundle-update-plugin";
const namespace = `${pluginName}-ns`;
Expand Down Expand Up @@ -53,7 +54,7 @@ export function cssBundleUpdatePlugin(channels: {

build.onLoad({ filter: /.*/, namespace }, async (args) => {
let cssBundleHref = await channels.cssBundleHref.result;
if (!cssBundleHref.ok) throw Error("canceled");
if (!cssBundleHref.ok) throw new Cancel("js");
let contents = await readFile(args.path, "utf8");

if (cssBundleHref.value) {
Expand Down
3 changes: 2 additions & 1 deletion packages/remix-dev/compiler/server/plugins/manifest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import jsesc from "jsesc";
import type * as Channel from "../../../channel";
import { type Manifest } from "../../../manifest";
import { assetsManifestVirtualModule } from "../virtualModules";
import { Cancel } from "../../cancel";

/**
* Creates a virtual module called `@remix-run/dev/assets-manifest` that exports
Expand All @@ -27,7 +28,7 @@ export function serverAssetsManifestPlugin(channels: {

build.onLoad({ filter }, async () => {
let manifest = await channels.manifest.result;
if (!manifest.ok) throw Error("canceled");
if (!manifest.ok) throw new Cancel("server");
return {
contents: `export default ${jsesc(manifest.value, {
es6: true,
Expand Down
14 changes: 10 additions & 4 deletions packages/remix-dev/compiler/utils/log.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import esbuild from "esbuild";

import { CANCEL_PREFIX } from "../cancel";

let toError = (thrown: unknown): Error => {
if (thrown instanceof Error) return thrown;
try {
Expand All @@ -21,10 +23,14 @@ let logEsbuildError = (error: esbuild.BuildFailure) => {
color: true,
});
warnings.forEach((w) => console.warn(w));
let errors = esbuild.formatMessagesSync(error.errors, {
kind: "error",
color: true,
});
let errors = esbuild.formatMessagesSync(
// Filter out cancelation errors
error.errors.filter((e) => !e.text.startsWith(CANCEL_PREFIX)),
{
kind: "error",
color: true,
}
);
errors.forEach((e) => console.error(e));
};

Expand Down

0 comments on commit 8cad4ee

Please sign in to comment.