fix(create-medusa-app): improved error messages (#4543)

* fix error messages

* format docs url based on current OS

* added changeset
This commit is contained in:
Shahed Nasser
2023-07-19 14:23:54 +02:00
committed by GitHub
parent 221f62dc4c
commit f325881227
4 changed files with 23 additions and 4 deletions
+5
View File
@@ -0,0 +1,5 @@
---
"create-medusa-app": patch
---
fix(create-medusa-app): improved error messages
@@ -53,11 +53,14 @@ export default async ({ repoUrl = "", seed, boilerplate }: CreateOptions) => {
}
const dbName = `medusa-${nanoid(4)}`
let isProjectCreated = false
let isDbInitialized = false
let printedMessage = false
processManager.onTerminated(async () => {
spinner.stop()
if (client) {
// prevent an error from occurring if
// client hasn't been declared yet
if (isDbInitialized && client) {
await client.end()
}
@@ -86,6 +89,7 @@ export default async ({ repoUrl = "", seed, boilerplate }: CreateOptions) => {
const projectName = await askForProjectName()
const { client, dbConnectionString } = await getDbClientAndCredentials(dbName)
isDbInitialized = true
const adminEmail = await askForAdminEmail(seed, boilerplate)
logMessage({
@@ -1,9 +1,11 @@
import { EOL } from "os"
import pg from "pg"
import postgresClient from "./postgres-client.js"
import inquirer from "inquirer"
import logMessage from "./log-message.js"
import formatConnectionString from "./format-connection-string.js"
import { Ora } from "ora"
import { getCurrentOs } from "./get-current-os.js"
type CreateDbOptions = {
client: pg.Client
@@ -80,9 +82,7 @@ export async function getDbClientAndCredentials(dbName: string): Promise<{
})
} catch (e) {
logMessage({
message:
"Couldn't connect to PostgreSQL. Make sure you have PostgreSQL installed and the credentials you provided are correct.${EOL}${EOL}" +
"You can learn how to install PostgreSQL here: https://docs.medusajs.com/development/backend/prepare-environment#postgresql",
message: `Couldn't connect to PostgreSQL. Make sure you have PostgreSQL installed and the credentials you provided are correct.${EOL}${EOL}You can learn how to install PostgreSQL here: https://docs.medusajs.com/development/backend/prepare-environment?os=${getCurrentOs()}#postgresql`,
type: "error",
})
}
@@ -0,0 +1,10 @@
export const getCurrentOs = (): string => {
switch (process.platform) {
case "darwin":
return "macos"
case "linux":
return "linux"
default:
return "windows"
}
}