FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Fix errors showing as success in Firestore commands by TomasMorton · Pull Request #7482 · firebase/firebase-tools · GitHub

1 change: 1 addition & 0 deletions CHANGELOG.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@
- Adds support for firealerts events in Eventarc emulator. (#7355)
- Released version firebase-tools-ui@1.13.0, which adds Emulator UI support for firealerts events.
- Improved errors when an incorrect service ID is passed to `firebase deploy --only dataconnect:serviceId`.
- Fixed display of errors in Firestore commands when using JSON or noninteractive modes. (#7482)
27 changes: 10 additions & 17 deletions src/commands/firestore-backups-schedules-create.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { Emulators } from "../emulator/types";
import { warnEmulatorNotSupported } from "../emulator/commandUtils";
import { FirestoreOptions } from "../firestore/options";
import { PrettyPrint } from "../firestore/pretty-print";
import { FirebaseError } from "../error";

export const command = new Command("firestore:backups:schedules:create")
.description("Create a backup schedule under your Cloud Firestore database.")
Expand All @@ -32,47 +33,39 @@ export const command = new Command("firestore:backups:schedules:create")
.before(warnEmulatorNotSupported, Emulators.FIRESTORE)
.action(async (options: FirestoreOptions) => {
const printer = new PrettyPrint();
const helpCommandText = "See firebase firestore:backups:schedules:create --help for more info.";

const databaseId = options.database || "(default)";

if (!options.retention) {
logger.error(
"Missing required flag --retention. See firebase firestore:backups:schedules:create --help for more info",
);
return;
throw new FirebaseError(`Missing required flag --retention. ${helpCommandText}`);
}
const retention = calculateRetention(options.retention);

if (!options.recurrence) {
logger.error(
"Missing required flag --recurrence. See firebase firestore:backups:schedules:create --help for more info",
);
return;
throw new FirebaseError(`Missing required flag --recurrence. ${helpCommandText}`);
}
const recurrenceType: types.RecurrenceType = options.recurrence;
if (
recurrenceType !== types.RecurrenceType.DAILY &&
recurrenceType !== types.RecurrenceType.WEEKLY
) {
logger.error(
"Invalid value for flag --recurrence. See firebase firestore:backups:schedules:create --help for more info",
);
return;
throw new FirebaseError(`Invalid value for flag --recurrence. ${helpCommandText}`);
}
let dailyRecurrence: Record<string, never> | undefined;
let weeklyRecurrence: WeeklyRecurrence | undefined;
if (options.recurrence === types.RecurrenceType.DAILY) {
dailyRecurrence = {};
if (options.dayOfWeek) {
logger.error("--day-of-week should not be provided if --recurrence is DAILY");
return;
throw new FirebaseError(
`--day-of-week should not be provided if --recurrence is DAILY. ${helpCommandText}`,
);
}
} else if (options.recurrence === types.RecurrenceType.WEEKLY) {
if (!options.dayOfWeek) {
logger.error(
"If --recurrence is WEEKLY, --day-of-week must be provided. See firebase firestore:backups:schedules:create --help for more info",
throw new FirebaseError(
`If --recurrence is WEEKLY, --day-of-week must be provided. ${helpCommandText}`,
);
return;
}
const day: DayOfWeek = options.dayOfWeek;
weeklyRecurrence = {
Expand Down
7 changes: 3 additions & 4 deletions src/commands/firestore-backups-schedules-update.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { Emulators } from "../emulator/types";
import { warnEmulatorNotSupported } from "../emulator/commandUtils";
import { FirestoreOptions } from "../firestore/options";
import { PrettyPrint } from "../firestore/pretty-print";
import { FirebaseError } from "../error";

export const command = new Command("firestore:backups:schedules:update <backupSchedule>")
.description("Update a backup schedule under your Cloud Firestore database.")
Expand All @@ -17,12 +18,10 @@ export const command = new Command("firestore:backups:schedules:update <backupSc
.before(warnEmulatorNotSupported, Emulators.FIRESTORE)
.action(async (backupScheduleName: string, options: FirestoreOptions) => {
const printer = new PrettyPrint();
const helpCommandText = "See firebase firestore:backups:schedules:update --help for more info.";

if (!options.retention) {
logger.error(
"Missing required flag --retention. See firebase firestore:backups:schedules:update --help for more info",
);
return;
throw new FirebaseError(`Missing required flag --retention. ${helpCommandText}`);
}
const retention = calculateRetention(options.retention);

Expand Down
18 changes: 7 additions & 11 deletions src/commands/firestore-databases-create.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { Emulators } from "../emulator/types";
import { warnEmulatorNotSupported } from "../emulator/commandUtils";
import { FirestoreOptions } from "../firestore/options";
import { PrettyPrint } from "../firestore/pretty-print";
import { FirebaseError } from "../error";

export const command = new Command("firestore:databases:create <database>")
.description("Create a database in your Firebase project.")
Expand All @@ -29,11 +30,10 @@ export const command = new Command("firestore:databases:create <database>")
.action(async (database: string, options: FirestoreOptions) => {
const api = new fsi.FirestoreApi();
const printer = new PrettyPrint();
const helpCommandText = "See firebase firestore:databases:create --help for more info.";

if (!options.location) {
logger.error(
"Missing required flag --location. See firebase firestore:databases:create --help for more info.",
);
return;
throw new FirebaseError(`Missing required flag --location. ${helpCommandText}`);
}
// Type is always Firestore Native since Firebase does not support Datastore Mode
const type: types.DatabaseType = types.DatabaseType.FIRESTORE_NATIVE;
Expand All @@ -42,10 +42,7 @@ export const command = new Command("firestore:databases:create <database>")
options.deleteProtection !== types.DatabaseDeleteProtectionStateOption.ENABLED &&
options.deleteProtection !== types.DatabaseDeleteProtectionStateOption.DISABLED
) {
logger.error(
"Invalid value for flag --delete-protection. See firebase firestore:databases:create --help for more info.",
);
return;
throw new FirebaseError(`Invalid value for flag --delete-protection. ${helpCommandText}`);
}
const deleteProtectionState: types.DatabaseDeleteProtectionState =
options.deleteProtection === types.DatabaseDeleteProtectionStateOption.ENABLED
Expand All @@ -57,10 +54,9 @@ export const command = new Command("firestore:databases:create <database>")
options.pointInTimeRecovery !== types.PointInTimeRecoveryEnablementOption.ENABLED &&
options.pointInTimeRecovery !== types.PointInTimeRecoveryEnablementOption.DISABLED
) {
logger.error(
"Invalid value for flag --point-in-time-recovery. See firebase firestore:databases:create --help for more info.",
throw new FirebaseError(
`Invalid value for flag --point-in-time-recovery. ${helpCommandText}`,
);
return;
}
const pointInTimeRecoveryEnablement: types.PointInTimeRecoveryEnablement =
options.pointInTimeRecovery === types.PointInTimeRecoveryEnablementOption.ENABLED
Expand Down
12 changes: 4 additions & 8 deletions src/commands/firestore-databases-restore.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { Emulators } from "../emulator/types";
import { warnEmulatorNotSupported } from "../emulator/commandUtils";
import { FirestoreOptions } from "../firestore/options";
import { PrettyPrint } from "../firestore/pretty-print";
import { FirebaseError } from "../error";

export const command = new Command("firestore:databases:restore")
.description("Restore a Firestore database in your Firebase project.")
Expand All @@ -19,20 +20,15 @@ export const command = new Command("firestore:databases:restore")
.action(async (options: FirestoreOptions) => {
const api = new fsi.FirestoreApi();
const printer = new PrettyPrint();
const helpCommandText = "See firebase firestore:databases:restore --help for more info.";

if (!options.database) {
logger.error(
"Missing required flag --database. See firebase firestore:databases:restore --help for more info",
);
return;
throw new FirebaseError(`Missing required flag --database. ${helpCommandText}`);
}
const databaseId = options.database;

if (!options.backup) {
logger.error(
"Missing required flag --backup. See firebase firestore:databases:restore --help for more info",
);
return;
throw new FirebaseError(`Missing required flag --backup. ${helpCommandText}`);
}
const backupName = options.backup;

Expand Down
17 changes: 6 additions & 11 deletions src/commands/firestore-databases-update.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { Emulators } from "../emulator/types";
import { warnEmulatorNotSupported } from "../emulator/commandUtils";
import { FirestoreOptions } from "../firestore/options";
import { PrettyPrint } from "../firestore/pretty-print";
import { FirebaseError } from "../error";

export const command = new Command("firestore:databases:update <database>")
.description(
Expand All @@ -28,22 +29,17 @@ export const command = new Command("firestore:databases:update <database>")
.action(async (database: string, options: FirestoreOptions) => {
const api = new fsi.FirestoreApi();
const printer = new PrettyPrint();
const helpCommandText = "See firebase firestore:databases:update --help for more info.";

if (!options.deleteProtection && !options.pointInTimeRecovery) {
logger.error(
"Missing properties to update. See firebase firestore:databases:update --help for more info.",
);
return;
throw new FirebaseError(`Missing properties to update. ${helpCommandText}`);
}
if (
options.deleteProtection &&
options.deleteProtection !== types.DatabaseDeleteProtectionStateOption.ENABLED &&
options.deleteProtection !== types.DatabaseDeleteProtectionStateOption.DISABLED
) {
logger.error(
"Invalid value for flag --delete-protection. See firebase firestore:databases:update --help for more info.",
);
return;
throw new FirebaseError(`Invalid value for flag --delete-protection. ${helpCommandText}`);
}
let deleteProtectionState: types.DatabaseDeleteProtectionState | undefined;
if (options.deleteProtection === types.DatabaseDeleteProtectionStateOption.ENABLED) {
Expand All @@ -57,10 +53,9 @@ export const command = new Command("firestore:databases:update <database>")
options.pointInTimeRecovery !== types.PointInTimeRecoveryEnablementOption.ENABLED &&
options.pointInTimeRecovery !== types.PointInTimeRecoveryEnablementOption.DISABLED
) {
logger.error(
"Invalid value for flag --point-in-time-recovery. See firebase firestore:databases:update --help for more info.",
throw new FirebaseError(
`Invalid value for flag --point-in-time-recovery. ${helpCommandText}`,
);
return;
}
let pointInTimeRecoveryEnablement: types.PointInTimeRecoveryEnablement | undefined;
if (options.pointInTimeRecovery === types.PointInTimeRecoveryEnablementOption.ENABLED) {
Expand Down
2 changes: 1 addition & 1 deletion src/commands/firestore-delete.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { requirePermissions } from "../requirePermissions";
import * as utils from "../utils";
import { FirestoreOptions } from "../firestore/options";

function confirmationMessage(deleteOp: FirestoreDelete, options: FirestoreOptions) {
function confirmationMessage(deleteOp: FirestoreDelete, options: FirestoreOptions): string {
if (options.allCollections) {
return (
"You are about to delete " +
Expand Down

Back | FazBrowse Home | New Git URL