Skip to content

Commit

Permalink
use custom error class (#1479)
Browse files Browse the repository at this point in the history
  • Loading branch information
c-ehrlich committed Jun 20, 2023
1 parent 8624126 commit bb7324c
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
5 changes: 5 additions & 0 deletions .changeset/funny-spoons-unite.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"create-t3-app": patch
---

use custom error class for IsTTYError
12 changes: 4 additions & 8 deletions cli/src/cli/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { type AvailablePackages } from "~/installers/index.js";
import { availablePackages } from "~/installers/index.js";
import { getVersion } from "~/utils/getT3Version.js";
import { getUserPkgManager } from "~/utils/getUserPkgManager.js";
import { IsTTYError } from "~/utils/isTTYError.js";
import { logger } from "~/utils/logger.js";
import { validateAppName } from "~/utils/validateAppName.js";
import { validateImportAlias } from "~/utils/validateImportAlias.js";
Expand Down Expand Up @@ -162,10 +163,7 @@ export const runCli = async () => {
using Git Bash. If that's that case, please use Git Bash from another terminal, such as Windows Terminal. Alternatively, you
can provide the arguments from the CLI directly: https://create.t3.gg/en/installation#experimental-usage to skip the prompts.`);

const error = new Error("Non-interactive environment");
// eslint-disable-next-line @typescript-eslint/no-explicit-any
(error as any).isTTYError = true;
throw error;
throw new IsTTYError("Non-interactive environment");
}

// if --CI flag is set, we are running in CI mode and should not prompt the user
Expand All @@ -188,11 +186,9 @@ export const runCli = async () => {
cliResults.flags.importAlias = await promptImportAlias();
}
} catch (err) {
// If the user is not calling create-t3-app from an interactive terminal, inquirer will throw an error with isTTYError = true
// If the user is not calling create-t3-app from an interactive terminal, inquirer will throw an IsTTYError
// If this happens, we catch the error, tell the user what has happened, and then continue to run the program with a default t3 app
// Otherwise we have to do some fancy namespace extension logic on the Error type which feels overkill for one line
// eslint-disable-next-line @typescript-eslint/no-explicit-any
if (err instanceof Error && (err as any).isTTYError) {
if (err instanceof IsTTYError) {
logger.warn(`
${CREATE_T3_APP} needs an interactive terminal to provide options`);

Expand Down
5 changes: 5 additions & 0 deletions cli/src/utils/isTTYError.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export class IsTTYError extends Error {
constructor(msg: string) {
super(msg);
}
}

1 comment on commit bb7324c

@vercel
Copy link

@vercel vercel bot commented on bb7324c Jun 20, 2023

Choose a reason for hiding this comment

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

Successfully deployed to the following URLs:

t3-upgrade – ./upgrade

t3-upgrade.vercel.app
t3-upgrade-t3-oss.vercel.app
t3-upgrade-git-next-t3-oss.vercel.app

Please sign in to comment.