Skip to content

Add handling for REQUIRE_FORCE issues. #8151

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Feb 10, 2025
20 changes: 20 additions & 0 deletions src/dataconnect/build.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,26 @@ describe("handleBuildErrors", () => {
dryRun: false,
expectErr: false,
},
{
desc: "Required force evolution error, force=false",
graphqlErr: [
{ message: "inaccessible error", extensions: { warningLevel: "REQUIRE_FORCE" } },
],
nonInteractive: false,
force: false,
dryRun: false,
expectErr: true,
},
{
desc: "Required force evolution error, force=true",
graphqlErr: [
{ message: "inaccessible error", extensions: { warningLevel: "REQUIRE_FORCE" } },
],
nonInteractive: false,
force: true,
dryRun: false,
expectErr: false,
},
];
for (const c of cases) {
it(c.desc, async () => {
Expand Down
11 changes: 11 additions & 0 deletions src/dataconnect/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import { prettify, prettifyWithWorkaround } from "./graphqlError";
import { DeploymentMetadata, GraphqlError } from "./types";

export async function build(

Check warning on line 10 in src/dataconnect/build.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Missing JSDoc comment
options: Options,
configDir: string,
dryRun?: boolean,
Expand All @@ -29,7 +29,7 @@
return buildResult?.metadata ?? {};
}

export async function handleBuildErrors(

Check warning on line 32 in src/dataconnect/build.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Missing return type on function

Check warning on line 32 in src/dataconnect/build.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Missing JSDoc comment
errors: GraphqlError[],
nonInteractive: boolean,
force: boolean,
Expand All @@ -41,6 +41,17 @@
`There are errors in your schema and connector files:\n${errors.map(prettify).join("\n")}`,
);
}

const requiredForces = errors.filter((w) => w.extensions?.warningLevel === "REQUIRE_FORCE");
if (requiredForces.length && !force) {
utils.logLabeledError(
"dataconnect",
`There are changes in your schema or connectors that will result in broken behavior:\n` +
prettifyWithWorkaround(requiredForces),
);
throw new FirebaseError("Rerun this command with --force to deploy these changes.");
}

const interactiveAcks = errors.filter((w) => w.extensions?.warningLevel === "INTERACTIVE_ACK");
const requiredAcks = errors.filter((w) => w.extensions?.warningLevel === "REQUIRE_ACK");
const choices = [
Expand All @@ -58,7 +69,7 @@
"Explicit acknowledgement required for breaking schema or connector changes. Rerun this command with --force to deploy these changes.",
);
} else if (!nonInteractive && !force && !dryRun) {
const result = await promptOnce({

Check warning on line 72 in src/dataconnect/build.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unsafe assignment of an `any` value
message: "Would you like to proceed with these breaking changes?",
type: "list",
choices,
Expand All @@ -76,7 +87,7 @@
interactiveAcks.map(prettify).join("\n"),
);
if (!nonInteractive && !force && !dryRun) {
const result = await promptOnce({

Check warning on line 90 in src/dataconnect/build.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unsafe assignment of an `any` value
message: "Would you like to proceed with these changes?",
type: "list",
choices,
Expand Down
6 changes: 4 additions & 2 deletions src/dataconnect/graphqlError.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { GraphqlError } from "./types";
import * as Table from "cli-table3";

export function prettify(err: GraphqlError): string {

Check warning on line 4 in src/dataconnect/graphqlError.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Missing JSDoc comment
const message = err.message;
let header = err.extensions?.file ?? "";
if (err.locations && err.locations.length) {
Expand All @@ -13,10 +13,12 @@
return header.length ? `${header}: ${message}` : message;
}

export function prettifyWithWorkaround(errs: GraphqlError[]): string {

Check warning on line 16 in src/dataconnect/graphqlError.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Missing JSDoc comment
const table = new Table({
head: ["Issue", "Workaround", "Reason"],
style: { head: ["yellow"] },
colWidths: [50, 50, 50],
wordWrap: true,
});
for (const e of errs) {
if (!e.extensions?.workarounds?.length) {
Expand All @@ -25,9 +27,9 @@
const workarounds = e.extensions.workarounds;
for (let i = 0; i < workarounds.length; i++) {
if (i === 0) {
table.push([prettify(e), workarounds[i].Description, workarounds[i].Reason]);
table.push([prettify(e), workarounds[i].description, workarounds[i].reason]);
} else {
table.push(["", workarounds[i].Description, workarounds[i].Reason]);
table.push(["", workarounds[i].description, workarounds[i].reason]);
}
}
}
Expand Down
9 changes: 4 additions & 5 deletions src/dataconnect/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,12 @@
destructive: boolean;
}

export type WarningLevel = "INTERACTIVE_ACK" | "REQUIRE_ACK";
export type WarningLevel = "INTERACTIVE_ACK" | "REQUIRE_ACK" | "REQUIRE_FORCE";

export interface Workaround {
// TODO: Make these lower-case after fixing the emulator, to match the style convention.
Description: string;
Reason: string;
ReplaceWith: string;
description: string;
reason: string;
replaceWith: string;
}

export interface GraphqlError {
Expand All @@ -90,7 +89,7 @@
file?: string;
warningLevel?: WarningLevel;
workarounds?: Workaround[];
[key: string]: any;

Check warning on line 92 in src/dataconnect/types.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unexpected any. Specify a different type
};
}
export interface BuildResult {
Expand All @@ -106,7 +105,7 @@
};
}

export function requiresVector(dm?: DeploymentMetadata): boolean {

Check warning on line 108 in src/dataconnect/types.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Missing JSDoc comment
return dm?.primaryDataSource?.postgres?.requiredExtensions?.includes("vector") ?? false;
}

Expand Down Expand Up @@ -194,7 +193,7 @@
connectorYaml: ConnectorYaml;
}

export function toDatasource(

Check warning on line 196 in src/dataconnect/types.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Missing JSDoc comment
projectId: string,
locationId: string,
ds: DatasourceYaml,
Expand Down
Loading