throw errors instead of returning rejected promises (#1019)

This commit is contained in:
Bryan Kendall
2018-11-19 09:46:54 -08:00
committed by GitHub
parent 6ca7ecab05
commit ba83d1678c

View File

@@ -1,21 +1,21 @@
"use strict"; "use strict";
var _ = require("lodash"); const _ = require("lodash");
const clc = require("cli-color"); const clc = require("cli-color");
const api = require("../../api"); const api = require("../../api");
const convertConfig = require("./convertConfig"); const convertConfig = require("./convertConfig");
const fsutils = require("../../fsutils");
const resolveProjectPath = require("../../resolveProjectPath");
const utils = require("../../utils");
const normalizedHostingConfigs = require("../../hosting/normalizedHostingConfigs");
const deploymentTool = require("../../deploymentTool"); const deploymentTool = require("../../deploymentTool");
const FirebaseError = require("../../error");
const fsutils = require("../../fsutils");
const normalizedHostingConfigs = require("../../hosting/normalizedHostingConfigs");
const resolveProjectPath = require("../../resolveProjectPath");
module.exports = function(context, options) { module.exports = function(context, options) {
// Allow the public directory to be overridden by the --public flag // Allow the public directory to be overridden by the --public flag
if (options.public) { if (options.public) {
if (_.isArray(options.config.get("hosting"))) { if (_.isArray(options.config.get("hosting"))) {
return utils.reject("Cannot specify --public option with multi-site configuration."); throw new FirebaseError("Cannot specify --public option with multi-site configuration.");
} }
// trigger legacy key import since public may not exist in firebase.json // trigger legacy key import since public may not exist in firebase.json
@@ -42,29 +42,24 @@ module.exports = function(context, options) {
if (cfg.target) { if (cfg.target) {
const matchingTargets = options.rc.requireTarget(options.project, "hosting", cfg.target); const matchingTargets = options.rc.requireTarget(options.project, "hosting", cfg.target);
if (matchingTargets.length > 1) { if (matchingTargets.length > 1) {
return utils.reject( throw new FirebaseError(
"Hosting target " + `Hosting target ${clc.bold(cfg.target)} is linked to multiple sites, ` +
clc.bold(cfg.target) + `but only one is permitted. ` +
" is linked to multiple sites, but only one is permitted. To clear, run:\n\n firebase target:clear hosting " + `To clear, run:\n\n firebase target:clear hosting ${cfg.target}`
cfg.target
); );
} }
deploy.site = matchingTargets[0]; deploy.site = matchingTargets[0];
} else if (cfg.site) { } else if (cfg.site) {
deploy.site = cfg.site; deploy.site = cfg.site;
} else { } else {
return utils.reject('Must supply either "site" or "target" in each "hosting" config.'); throw new FirebaseError('Must supply either "site" or "target" in each "hosting" config.');
} }
if (!fsutils.dirExistsSync(resolveProjectPath(options.cwd, cfg.public))) { if (!fsutils.dirExistsSync(resolveProjectPath(options.cwd, cfg.public))) {
return utils.reject( throw new FirebaseError(
"Specified public directory '" + `Specified public directory '${cfg.public}' does not exist, ` +
cfg.public + `can't deploy hosting to site ${deploy.site}`,
"'does not exist, can't deploy hosting to site " + { exit: 1 }
deploy.site,
{
exit: 1,
}
); );
} }