import chalk from "chalk"; import terminalLink from "terminal-link"; import { getRandomElement } from "."; import type { ErrorContext } from "../types"; const Discord = terminalLink( `${chalk.hex("#5865F2")("Discord")}`, chalk.hex("#5865F2")("https://discord.gg/wMnhVkpDCC") ); const GitHub = terminalLink( `${chalk.hex("#6e5494")("GitHub")}`, chalk.hex("#6e5494")("coming soon!") ); const SimpleErrorHelpMessages = [ `No worries! It seems like a minor mistake. If you need assistance, don't hesitate to reach out on ${Discord} or ${GitHub}.`, `Just a small hiccup. Take your time, and if you run into any roadblocks, we're here to help on ${Discord} or ${GitHub}.`, `It appears to be a minor issue. Feel free to reach out if you need guidance on ${Discord} or ${GitHub}.`, `Seems like a simple mistake. If you're still stuck, we're available to assist on ${Discord} or ${GitHub}.`, ]; const TrickyErrorHelpMessages = [ `Looks like it might be a bit tricky. Take your time, and know that we're here to support you on ${Discord} or ${GitHub}.`, `Seems like it could be a tricky one. If you need assistance, we're available on ${Discord} or ${GitHub}`, `Looks like a tricky one. Remember, you're not alone—reach out on ${Discord} or ${GitHub} if you need a hand.`, `Oof! this can be hard to debug sometimes. if you get stuck, we'll be there to resolve the issue ${Discord} or ${GitHub} :) `, ]; const OhShitErrorHelpMessages = [ `Looks like a tough spot! Take your time, and remember, we're here to help on ${Discord} or ${GitHub}.`, `This seems like a serious issue. Don't worry; we'll get through it together. Reach out on ${Discord} or ${GitHub} if you need support.`, `Big problem, huh? Take a deep breath, and reach out on ${Discord} or ${GitHub} whenever you're ready. We're here for you.`, `Complex error, but don't panic. Reach out on ${Discord} or ${GitHub}, and we'll work through it together.`, ]; export const getFormattedError = ({ coreMessage, highlightAffected, complexity, humanMessage, docs, proTip, stackTrace, }: ErrorContext) => { let output = `\n\t`; output += `${chalk.red(coreMessage)}`; if (highlightAffected) { output += `\n\t${chalk.bold(highlightAffected.title)} -> ${chalk.bgBlack( chalk.red(highlightAffected.value) )}`; } if (complexity) { //forceOverrides for testing purposes switch (complexity) { case "simple": { output += `\n\t${getRandomElement(SimpleErrorHelpMessages)}`; break; } case "tricky": { output += `\n\t${getRandomElement(TrickyErrorHelpMessages)}`; break; } case "oh-shit": { output += `\n\t${getRandomElement(OhShitErrorHelpMessages)}`; break; } } } if (humanMessage) { output += `\n\t${humanMessage}`; } if (docs) { output += `\n\n\t${chalk.bold("Helpful Docs - ")} ${chalk.grey(docs)}`; } if (proTip) { output += `\n\t${chalk.green(`${chalk.bold("Pro Tip - ")} ${proTip}`)}`; } if (stackTrace) { output += `\n${chalk.red(stackTrace)}`; } return (output += `\n`); };