Skip to content

Commit

Permalink
chore: unify error usage
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelDeBoey committed Dec 1, 2022
1 parent 95b4b28 commit f782d75
Show file tree
Hide file tree
Showing 15 changed files with 35 additions and 35 deletions.
4 changes: 2 additions & 2 deletions docs/guides/optimistic-ui.md
Original file line number Diff line number Diff line change
Expand Up @@ -201,8 +201,8 @@ export const action: ActionFunction = async ({
try {
const project = await createProject(newProject);
return redirect(`/projects/${project.id}`);
} catch (e) {
console.error(e);
} catch (error) {
console.error(error);
return json("Sorry, we couldn't create the project", {
status: 500,
});
Expand Down
2 changes: 1 addition & 1 deletion integration/form-data-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ test.beforeAll(async () => {
export async function action({ request }) {
try {
await request.formData()
} catch (err) {
} catch {
return json("no pizza");
}
return json("pizza");
Expand Down
2 changes: 1 addition & 1 deletion integration/server-source-maps-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ test.beforeAll(async () => {
export function loader() {
try {
throw new Error("💩");
} catch (err) {
} catch {
return json(err.stack);
}
}
Expand Down
8 changes: 4 additions & 4 deletions packages/remix-cloudflare-pages/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,10 @@ export function createPagesFunctionHandler<Env = any>({
return async (context: EventContext<Env, any, any>) => {
try {
return await handleFetch(context);
} catch (e) {
if (process.env.NODE_ENV === "development" && e instanceof Error) {
console.error(e);
return new Response(e.message || e.toString(), {
} catch (error: unknown) {
if (process.env.NODE_ENV === "development" && error instanceof Error) {
console.error(error);
return new Response(error.message || error.toString(), {
status: 500,
});
}
Expand Down
6 changes: 3 additions & 3 deletions packages/remix-deno/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ export function createRequestHandler<
const loadContext = await getLoadContext?.(request);

return handleRequest(request, loadContext);
} catch (e) {
console.error(e);
} catch (error) {
console.error(error);

return new Response("Internal Error", { status: 500 });
}
Expand All @@ -53,7 +53,7 @@ export async function serveStaticFiles(
cacheControl?: string | ((url: URL) => string);
publicDir?: string;
assetsPublicPath?: string;
},
}
) {
const url = new URL(request.url);

Expand Down
12 changes: 6 additions & 6 deletions packages/remix-dev/__tests__/create-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -665,8 +665,8 @@ describe("the create command", () => {
"--typescript",
]);
return res;
} catch (err) {
throw err;
} catch (error) {
throw error;
}
}).rejects.toMatchInlineSnapshot(
`[Error: 🚨 The template could not be verified because you do not have access to the repository. Please double check the access rights of this repo and try again.]`
Expand Down Expand Up @@ -822,7 +822,7 @@ describe("the create command", () => {
});
it("uses the proxy from env var", async () => {
let projectDir = await getProjectDir("template");
let err: Error | undefined;
let error: Error | undefined;
let prevProxy = process.env.HTTPS_PROXY;
try {
process.env.HTTPS_PROXY = "http://127.0.0.1:33128";
Expand All @@ -834,12 +834,12 @@ describe("the create command", () => {
"--no-install",
"--typescript",
]);
} catch (e) {
err = e;
} catch (err) {
error = err;
} finally {
process.env.HTTPS_PROXY = prevProxy;
}
expect(err?.message).toMatch("127.0.0.1:33");
expect(error?.message).toMatch("127.0.0.1:33");
});
});
});
Expand Down
6 changes: 3 additions & 3 deletions packages/remix-dev/cli/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ export async function createApp({
let appPkg: any;
try {
appPkg = require(pkgJsonPath);
} catch (err) {
} catch {
throw Error(
"🚨 The provided template must be a Remix project with a `package.json` " +
`file, but that file does not exist in ${pkgJsonPath}.`
Expand Down Expand Up @@ -244,12 +244,12 @@ async function extractLocalTarball(
gunzip(),
tar.extract(projectDir, { strip: 1 })
);
} catch (err) {
} catch (error: unknown) {
throw Error(
"🚨 There was a problem extracting the file from the provided template.\n\n" +
` Template filepath: \`${filePath}\`\n` +
` Destination directory: \`${projectDir}\`\n` +
` ${err}`
` ${error}`
);
}
}
Expand Down
4 changes: 2 additions & 2 deletions packages/remix-dev/compiler/remixCompiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ export const compile = async (
let browserPromise = compiler.browser.compile(assetsManifestChannel);
let serverPromise = compiler.server.compile(assetsManifestChannel);
await Promise.all([browserPromise, serverPromise]);
} catch (err) {
options.onCompileFailure?.(err as Error);
} catch (error: unknown) {
options.onCompileFailure?.(error as Error);
}
};

Expand Down
2 changes: 1 addition & 1 deletion packages/remix-dev/devServer/serve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ function purgeAppRequireCache(buildPath: string) {
function tryImport(packageName: string) {
try {
return require(packageName);
} catch (err) {
} catch {
throw new Error(
`Could not locate ${packageName}. Verify that you have it installed to use the dev command.`
);
Expand Down
2 changes: 1 addition & 1 deletion packages/remix-dev/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export async function loadEnv(rootDirectory: string): Promise<void> {
let envPath = path.join(rootDirectory, ".env");
try {
await fse.readFile(envPath);
} catch (e) {
} catch {
return;
}

Expand Down
2 changes: 1 addition & 1 deletion rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module.exports = function rollup(options) {
let configPath = path.join("packages", dir, "rollup.config.js");
try {
fs.readFileSync(configPath);
} catch (e) {
} catch {
return [];
}
let packageBuild = require(`.${path.sep}${configPath}`);
Expand Down
2 changes: 1 addition & 1 deletion rollup.utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ if (process.env.REMIX_LOCAL_BUILD_DIRECTORY) {
);
try {
fse.readdirSync(path.join(appDir, "node_modules"));
} catch (e) {
} catch {
console.error(
"Oops! You pointed REMIX_LOCAL_BUILD_DIRECTORY to a directory that " +
"does not have a node_modules/ folder. Please `npm install` in that " +
Expand Down
4 changes: 2 additions & 2 deletions scripts/copy-build-to-dist.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ if (process.env.REMIX_LOCAL_BUILD_DIRECTORY) {
let appDir = path.join(ROOT_DIR, process.env.REMIX_LOCAL_BUILD_DIRECTORY);
try {
fse.readdirSync(path.join(appDir, "node_modules"));
} catch (e) {
} catch {
console.error(
"Oops! You pointed `REMIX_LOCAL_BUILD_DIRECTORY` to a directory that " +
"does not have a `node_modules` folder. Please `npm install` in that " +
Expand Down Expand Up @@ -62,7 +62,7 @@ async function copyBuildToDist() {
});
})()
);
} catch (e) {}
} catch {}
}

// Write an export shim for @remix-run/node/globals types
Expand Down
12 changes: 6 additions & 6 deletions scripts/release.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ async function execStart(nextVersion) {
await gitPull("dev");
try {
checkoutNewBranch(releaseBranch);
} catch (e) {
} catch {
throw Error(
`Branch ${chalk.bold(
releaseBranch
Expand Down Expand Up @@ -243,10 +243,10 @@ async function gitMerge(from, to, opts = {}) {
let summary;
try {
summary = await git.merge([from]);
} catch (err) {
savedError = err;
} catch (error) {
savedError = error;
// @ts-ignore
summary = err.git;
summary = error.git;
}

if (summary.conflicts.length > 0) {
Expand Down Expand Up @@ -281,9 +281,9 @@ async function gitPull(branch) {
console.error(chalk.red("Merge failed.\n"));
throw Error(resp);
}
} catch (e) {
} catch (error) {
console.error(chalk.red(`Error rebasing to origin/${branch}`));
throw e;
throw error;
}
}

Expand Down
2 changes: 1 addition & 1 deletion scripts/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ async function updatePackageConfig(packageName, transform) {
}
transform(json);
await jsonfile.writeFile(file, json, { spaces: 2 });
} catch (err) {
} catch {
return;
}
}
Expand Down

0 comments on commit f782d75

Please sign in to comment.