{"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":";;;;;AAKA,MAAMA,OAAAA,GAAU,CAACC,GAAAA,GAA+BA,GAAAA,YAAeC;AAE/D;;;;;IAMA,MAAMC,wBAAwB,CAACF,GAAAA,GAAAA;IAC7BG,OAAAA,CAAQC,KAAK,CACXC,KAAAA,CAAMC,GAAG,CACP,CAAC,QAAQ,CAAC,EACV,oFAAA,EACAC,E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