Skip to content

Commit 2bfb61b

Browse files
authored
Add handling for REQUIRE_FORCE issues. (#8151)
* Add handling for REQUIRE_FORCE issues. * Add unit tests. * Fix + some formatting. * Make formatting fit a little better inside VSCode terminal. * Remove merge conflict markings.
1 parent ab42564 commit 2bfb61b

File tree

4 files changed

+39
-7
lines changed

4 files changed

+39
-7
lines changed

src/dataconnect/build.spec.ts

+20
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,26 @@ describe("handleBuildErrors", () => {
126126
dryRun: false,
127127
expectErr: false,
128128
},
129+
{
130+
desc: "Required force evolution error, force=false",
131+
graphqlErr: [
132+
{ message: "inaccessible error", extensions: { warningLevel: "REQUIRE_FORCE" } },
133+
],
134+
nonInteractive: false,
135+
force: false,
136+
dryRun: false,
137+
expectErr: true,
138+
},
139+
{
140+
desc: "Required force evolution error, force=true",
141+
graphqlErr: [
142+
{ message: "inaccessible error", extensions: { warningLevel: "REQUIRE_FORCE" } },
143+
],
144+
nonInteractive: false,
145+
force: true,
146+
dryRun: false,
147+
expectErr: false,
148+
},
129149
];
130150
for (const c of cases) {
131151
it(c.desc, async () => {

src/dataconnect/build.ts

+11
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,17 @@ export async function handleBuildErrors(
4141
`There are errors in your schema and connector files:\n${errors.map(prettify).join("\n")}`,
4242
);
4343
}
44+
45+
const requiredForces = errors.filter((w) => w.extensions?.warningLevel === "REQUIRE_FORCE");
46+
if (requiredForces.length && !force) {
47+
utils.logLabeledError(
48+
"dataconnect",
49+
`There are changes in your schema or connectors that will result in broken behavior:\n` +
50+
prettifyWithWorkaround(requiredForces),
51+
);
52+
throw new FirebaseError("Rerun this command with --force to deploy these changes.");
53+
}
54+
4455
const interactiveAcks = errors.filter((w) => w.extensions?.warningLevel === "INTERACTIVE_ACK");
4556
const requiredAcks = errors.filter((w) => w.extensions?.warningLevel === "REQUIRE_ACK");
4657
const choices = [

src/dataconnect/graphqlError.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ export function prettifyWithWorkaround(errs: GraphqlError[]): string {
1717
const table = new Table({
1818
head: ["Issue", "Workaround", "Reason"],
1919
style: { head: ["yellow"] },
20+
colWidths: [50, 50, 50],
21+
wordWrap: true,
2022
});
2123
for (const e of errs) {
2224
if (!e.extensions?.workarounds?.length) {
@@ -25,9 +27,9 @@ export function prettifyWithWorkaround(errs: GraphqlError[]): string {
2527
const workarounds = e.extensions.workarounds;
2628
for (let i = 0; i < workarounds.length; i++) {
2729
if (i === 0) {
28-
table.push([prettify(e), workarounds[i].Description, workarounds[i].Reason]);
30+
table.push([prettify(e), workarounds[i].description, workarounds[i].reason]);
2931
} else {
30-
table.push(["", workarounds[i].Description, workarounds[i].Reason]);
32+
table.push(["", workarounds[i].description, workarounds[i].reason]);
3133
}
3234
}
3335
}

src/dataconnect/types.ts

+4-5
Original file line numberDiff line numberDiff line change
@@ -71,13 +71,12 @@ export interface Diff {
7171
destructive: boolean;
7272
}
7373

74-
export type WarningLevel = "INTERACTIVE_ACK" | "REQUIRE_ACK";
74+
export type WarningLevel = "INTERACTIVE_ACK" | "REQUIRE_ACK" | "REQUIRE_FORCE";
7575

7676
export interface Workaround {
77-
// TODO: Make these lower-case after fixing the emulator, to match the style convention.
78-
Description: string;
79-
Reason: string;
80-
ReplaceWith: string;
77+
description: string;
78+
reason: string;
79+
replaceWith: string;
8180
}
8281

8382
export interface GraphqlError {

0 commit comments

Comments
 (0)