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 7, 2022
1 parent 46b0621 commit f39d643
Show file tree
Hide file tree
Showing 31 changed files with 61 additions and 61 deletions.
4 changes: 2 additions & 2 deletions docs/guides/optimistic-ui.md
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,8 @@ export const action = async ({ request }: ActionArgs) => {
try {
const project = await createProject(newProject);
return redirect(`/projects/${project.id}`);
} catch (e: unknown) {
console.error(e);
} catch (error: unknown) {
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
2 changes: 1 addition & 1 deletion packages/remix-cloudflare-workers/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ export async function handleAsset(
cacheControl,
...options,
});
} catch (error) {
} catch (error: unknown) {
if (
error instanceof MethodNotAllowedError ||
error instanceof NotFoundError
Expand Down
12 changes: 6 additions & 6 deletions packages/remix-deno/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ function defaultCacheControl(url: URL, assetsPublicPath = "/build/") {
}

export function createRequestHandler<
Context extends AppLoadContext | undefined = undefined,
Context extends AppLoadContext | undefined = undefined
>({
build,
mode,
Expand All @@ -29,8 +29,8 @@ export function createRequestHandler<
const loadContext = await getLoadContext?.(request);

return handleRequest(request, loadContext);
} catch (e) {
console.error(e);
} catch (error: unknown) {
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 Expand Up @@ -84,7 +84,7 @@ export async function serveStaticFiles(
}

export function createRequestHandlerWithStaticFiles<
Context extends AppLoadContext | undefined = undefined,
Context extends AppLoadContext | undefined = undefined
>({
build,
mode,
Expand All @@ -108,7 +108,7 @@ export function createRequestHandlerWithStaticFiles<
return async (request: Request) => {
try {
return await serveStaticFiles(request, staticFiles);
} catch (error) {
} catch (error: unknown) {
if (!(error instanceof FileNotFoundError)) {
throw error;
}
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: unknown) {
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
2 changes: 1 addition & 1 deletion packages/remix-dev/__tests__/utils/withApp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const retry = async (
) => {
try {
await callback();
} catch (error) {
} catch (error: unknown) {
if (times === 0) throw error;
setTimeout(() => retry(callback, times - 1), delayMs);
}
Expand Down
4 changes: 2 additions & 2 deletions packages/remix-dev/cli/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ export async function init(
if (deleteScript) {
await fse.remove(initScriptDir);
}
} catch (error) {
} catch (error: unknown) {
if (error instanceof Error) {
error.message = `${colors.error("🚨 Oops, remix.init failed")}\n\n${
error.message
Expand Down Expand Up @@ -222,7 +222,7 @@ export async function codemod(
dry,
force,
});
} catch (error) {
} catch (error: unknown) {
if (error instanceof CodemodError) {
console.error(`${colors.red("Error:")} ${error.message}`);
if (error.additionalInfo) console.info(colors.gray(error.additionalInfo));
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
2 changes: 1 addition & 1 deletion packages/remix-dev/cli/migrate/jscodeshift.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export const run = async <TransformOptions extends Options = Options>({
try {
let { error } = await jscodeshift(transformPath, files, options);
return error === 0;
} catch (error) {
} catch (error: unknown) {
return false;
}
};
2 changes: 1 addition & 1 deletion packages/remix-dev/cli/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ export async function run(argv: string[] = process.argv.slice(2)) {
try {
await validateNewProjectPath(String(input));
return true;
} catch (error) {
} catch (error: unknown) {
if (error instanceof Error && error.message) {
return error.message;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/remix-dev/codemod/utils/task.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export const task = async <Result>(
let result = await callback(spinner);
spinner.succeed(typeof succeed === "string" ? succeed : succeed(result));
return result;
} catch (error) {
} catch (error: unknown) {
if (error instanceof CodemodError) {
spinner.fail(error.message);
if (error.additionalInfo) log.info(error.additionalInfo);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export function serverBareModulesPlugin(
) {
try {
require.resolve(path);
} catch (error) {
} catch (error: unknown) {
onWarning(
`The path "${path}" is imported in ` +
`${relative(process.cwd(), importer)} but ` +
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
4 changes: 2 additions & 2 deletions packages/remix-dev/compiler/routeExports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export async function getRouteModuleExports(
let cached: CachedRouteExports | null = null;
try {
cached = await cache.getJson(config.cacheDirectory, key);
} catch (error) {
} catch (error: unknown) {
// Ignore cache read errors.
}

Expand All @@ -28,7 +28,7 @@ export async function getRouteModuleExports(
cached = { hash, exports };
try {
await cache.putJson(config.cacheDirectory, key, cached);
} catch (error) {
} catch (error: unknown) {
// Ignore cache put errors.
}
}
Expand Down
4 changes: 2 additions & 2 deletions packages/remix-dev/compiler/watch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export async function watch(

try {
config = await readConfig(config.rootDirectory);
} catch (error) {
} catch (error: unknown) {
onCompileFailure(error as Error);
return;
}
Expand Down Expand Up @@ -110,7 +110,7 @@ export async function watch(

try {
config = await readConfig(config.rootDirectory);
} catch (error) {
} catch (error: unknown) {
onCompileFailure(error as Error);
return;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/remix-dev/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ export async function readConfig(
appConfigModule = await import(pathToFileURL(configFile).href);
}
appConfig = appConfigModule?.default || appConfigModule;
} catch (error) {
} catch (error: unknown) {
throw new Error(
`Error loading Remix config at ${configFile}\n${String(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 packages/remix-express/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export function createRequestHandler({
)) as NodeResponse;

await sendRemixResponse(res, response);
} catch (error) {
} catch (error: unknown) {
// Express doesn't support async functions, so we have to pass along the
// error manually using next().
next(error);
Expand Down
2 changes: 1 addition & 1 deletion packages/remix-react/routeModules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ export async function loadRouteModule(
let routeModule = await import(/* webpackIgnore: true */ route.module);
routeModulesCache[route.id] = routeModule;
return routeModule;
} catch (error) {
} catch (error: unknown) {
// User got caught in the middle of a deploy and the CDN no longer has the
// asset we're trying to import! Reload from the server and the user
// (should) get the new manifest--unless the developer purged the static
Expand Down
2 changes: 1 addition & 1 deletion packages/remix-react/scroll-restoration.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export function ScrollRestoration(props: ScriptProps) {
if (typeof storedY === "number") {
window.scrollTo(0, storedY);
}
} catch (error) {
} catch (error: unknown) {
console.error(error);
sessionStorage.removeItem(STORAGE_KEY);
}
Expand Down
4 changes: 2 additions & 2 deletions packages/remix-react/transition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1461,7 +1461,7 @@ async function callLoader(match: ClientMatch, url: URL, signal: AbortSignal) {
let { params } = match;
let value = await match.route.loader({ params, url, signal });
return { match, value };
} catch (error) {
} catch (error: unknown) {
return { match, value: error };
}
}
Expand All @@ -1479,7 +1479,7 @@ async function callAction(
signal,
});
return { match, value };
} catch (error) {
} catch (error: unknown) {
return { match, value: error };
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/remix-server-runtime/cookies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ function encodeData(value: any): string {
function decodeData(value: string): any {
try {
return JSON.parse(decodeURIComponent(myEscape(atob(value))));
} catch (error) {
} catch (error: unknown) {
return {};
}
}
Expand Down
8 changes: 4 additions & 4 deletions packages/remix-server-runtime/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ async function handleDataRequestRR(
}

return response;
} catch (error) {
} catch (error: unknown) {
if (error instanceof Response) {
error.headers.set("X-Remix-Catch", "yes");
return error;
Expand Down Expand Up @@ -209,7 +209,7 @@ async function handleDocumentRequestRR(
let context;
try {
context = await staticHandler.query(request);
} catch (error) {
} catch (error: unknown) {
if (!request.signal.aborted && serverMode !== ServerMode.Test) {
console.error(error);
}
Expand Down Expand Up @@ -344,7 +344,7 @@ async function handleDocumentRequestRR(
return await handleDocumentRequestFunction(
...handleDocumentRequestParameters
);
} catch (error) {
} catch (error: unknown) {
handleDocumentRequestParameters[1] = 500;
appState.trackBoundaries = false;
appState.error = await serializeError(error as Error);
Expand Down Expand Up @@ -377,7 +377,7 @@ async function handleResourceRequestRR(
"Expected a Response to be returned from queryRoute"
);
return response;
} catch (error) {
} catch (error: unknown) {
if (error instanceof Response) {
// Note: Not functionally required but ensures that our response headers
// match identically to what Remix returns
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

0 comments on commit f39d643

Please sign in to comment.