{"version":3,"file":"errors.mjs","sources":["../../../../src/node/core/errors.ts"],"sourcesContent":["import boxen from 'boxen';\nimport chalk from 'chalk';\nimport os from 'node:os';\nimport { errors } from '@strapi/utils';\n\nconst isError = (err: unknown): err is Error => err instanceof Error;\n\n/**\n * @description Handle unexpected errors. No, but really, your CLI should anticipate error cases.\n * If a user hits an error we don't expect, then we need to flag to them that this is not normal\n * and they should use the `--debug` flag to get more information (assuming you've implemented this\n * in your action).\n */\nconst handleUnexpectedError = (err: unknown) => {\n  console.error(\n    chalk.red(\n      `[ERROR] `,\n      'There seems to be an unexpected error, try again with --debug for more information',\n      os.EOL\n    )\n  );\n\n  if (isError(err) && err.stack) {\n    // eslint-disable-next-line no-console\n    console.log(\n      chalk.red(\n        boxen(err.stack, {\n          padding: 1,\n          align: 'left',\n        })\n      )\n    );\n  }\n\n  if (err instanceof errors.YupValidationError) {\n    const message = [];\n    const size = err.details.errors.length;\n\n    for (const error of err.details.errors) {\n      // No need to repeat the error message as it's the same as the err.message\n      if (size === 1) {\n        message.push(`  value: ${error.value}`);\n        continue;\n      }\n\n      message.push(\n        [`  [${error.name}]`, `    message: ${error.message}`, `      value: ${error.value}`].join(\n          '\\n'\n        )\n      );\n    }\n\n    console.log(\n      chalk.red(\n        boxen(['Details:', message.join('\\n\\n')].join('\\n'), {\n          padding: 1,\n          align: 'left',\n        })\n      )\n    );\n  }\n\n  process.exit(1);\n};\n\nexport { handleUnexpectedError, isError };\n"],"names":["isError","err","Error","handleUnexpectedError","console","error","chalk","red","os","EOL","stack","log","boxen","padding","align","errors","YupValidationError","message","size","details","length","push","value","name","join","process","exit"],"mappings":";;;;;AAKMA,MAAAA,OAAAA,GAAU,CAACC,GAAAA,GAA+BA,GAAeC,YAAAA;AAE/D;;;;;IAMA,MAAMC,wBAAwB,CAACF,GAAAA,GAAAA;IAC7BG,OAAQC,CAAAA,KAAK,CACXC,KAAAA,CAAMC,GAAG,CACP,CAAC,QAAQ,CAAC,EACV,oFACAC,EAAAA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