UNPKG

eas-cli

Version:

EAS command line tool

93 lines (92 loc) 4.09 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.handleMetadataError = exports.logMetadataValidationError = exports.MetadataDownloadError = exports.MetadataUploadError = exports.MetadataValidationError = void 0; const tslib_1 = require("tslib"); const chalk_1 = tslib_1.__importDefault(require("chalk")); const log_1 = tslib_1.__importStar(require("../log")); /** * Before syncing data to the ASC API, we need to validate the metadata config. * This error represents unrecoverable issues before syncing that data, * and should contain useful information for the user to solve before trying again. */ class MetadataValidationError extends Error { errors; constructor(message, errors = []) { super(message ?? 'Store configuration validation failed'); this.errors = errors; } } exports.MetadataValidationError = MetadataValidationError; /** * If a single entity failed to update, we don't block the other entities from uploading. * We still attempt to update the data in the stores as much as possible. * Because of that, we keep track of any errors encountered and throw this generic error. * It contains that list of encountered errors to present to the user. */ class MetadataUploadError extends Error { errors; executionId; constructor(errors, executionId) { super(`Store configuration upload encountered ${errors.length === 1 ? 'an error' : `${errors.length} errors`}.`); this.errors = errors; this.executionId = executionId; } } exports.MetadataUploadError = MetadataUploadError; /** * If a single entity failed to download, we don't block the other entities from downloading. * We sill attempt to pull in the data from the stores as much as possible. * Because of that, we keep track of any errors envountered and throw this generic error. * It contains that list of encountered errors to present to the user. */ class MetadataDownloadError extends Error { errors; executionId; constructor(errors, executionId) { super(`Store configuration download encountered ${errors.length === 1 ? 'an error' : `${errors.length} errors`}.`); this.errors = errors; this.executionId = executionId; } } exports.MetadataDownloadError = MetadataDownloadError; /** * Log the encountered metadata validation error in detail for the user. * This should help communicate any possible configuration error and help the user resolve it. */ function logMetadataValidationError(error) { log_1.default.newLine(); log_1.default.error(chalk_1.default.bold(error.message)); if (error.errors?.length > 0) { // TODO(cedric): group errors by property to make multiple errors for same property more readable for (const err of error.errors) { log_1.default.log(` - ${chalk_1.default.bold(`$.${err.path.join('.')}`)} ${err.message}`); } } } exports.logMetadataValidationError = logMetadataValidationError; /** * Handle a thrown metadata error by informing the user what went wrong. * If a normal error is thrown, this method will re-throw that error to avoid consuming it. */ function handleMetadataError(error) { if (error instanceof MetadataValidationError) { logMetadataValidationError(error); return; } if (error instanceof MetadataDownloadError || error instanceof MetadataUploadError) { log_1.default.newLine(); log_1.default.error(chalk_1.default.bold(error.message)); if (error.errors?.length > 0) { log_1.default.newLine(); log_1.default.error(error.errors.map(err => err.message).join('\n\n')); } log_1.default.newLine(); log_1.default.log('Check the logs for any configuration issues.'); log_1.default.log('If this issue persists, open a new issue at:'); // TODO: add execution ID to the issue template link log_1.default.log((0, log_1.link)('https://github.com/expo/eas-cli')); return; } throw error; } exports.handleMetadataError = handleMetadataError;