From 4dd496fd6b0aaeabea780a75827df310cf9f0db7 Mon Sep 17 00:00:00 2001 From: Rosalyn Tan Date: Wed, 29 Jan 2025 15:03:51 -0800 Subject: [PATCH 1/5] Add handling for REQUIRE_FORCE issues. --- src/dataconnect/build.ts | 11 +++++++++++ src/dataconnect/types.ts | 2 +- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/dataconnect/build.ts b/src/dataconnect/build.ts index fb7b3055f9c..3f7e369ad45 100644 --- a/src/dataconnect/build.ts +++ b/src/dataconnect/build.ts @@ -41,6 +41,17 @@ export async function handleBuildErrors( `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) { + 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 = [ diff --git a/src/dataconnect/types.ts b/src/dataconnect/types.ts index ddd9c6e9e3b..19c8f3d21cd 100644 --- a/src/dataconnect/types.ts +++ b/src/dataconnect/types.ts @@ -71,7 +71,7 @@ export interface Diff { 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. From e89ad49bbd56bf742e05c03aaffe1b52ff1b7c27 Mon Sep 17 00:00:00 2001 From: Rosalyn Tan Date: Wed, 29 Jan 2025 15:37:10 -0800 Subject: [PATCH 2/5] Add unit tests. --- src/dataconnect/build.spec.ts | 20 ++++++++++++++++++++ src/dataconnect/build.ts | 2 +- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/dataconnect/build.spec.ts b/src/dataconnect/build.spec.ts index 94144c4bddf..533f80723a6 100644 --- a/src/dataconnect/build.spec.ts +++ b/src/dataconnect/build.spec.ts @@ -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 () => { diff --git a/src/dataconnect/build.ts b/src/dataconnect/build.ts index 3f7e369ad45..bd67e0760a0 100644 --- a/src/dataconnect/build.ts +++ b/src/dataconnect/build.ts @@ -43,7 +43,7 @@ export async function handleBuildErrors( } const requiredForces = errors.filter((w) => w.extensions?.warningLevel === "REQUIRE_FORCE"); - if (requiredForces.length) { + if (requiredForces.length && !force) { utils.logLabeledError( "dataconnect", `There are changes in your schema or connectors that will result in broken behavior:\n` + From 2510b90a3960a74cf4d546fc0661a03e31de5a80 Mon Sep 17 00:00:00 2001 From: Rosalyn Tan Date: Thu, 30 Jan 2025 14:51:44 -0800 Subject: [PATCH 3/5] Fix + some formatting. --- src/dataconnect/graphqlError.ts | 8 +++++--- src/dataconnect/types.ts | 7 +++---- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/dataconnect/graphqlError.ts b/src/dataconnect/graphqlError.ts index 6d3ae683fe9..dd55ab6ef74 100644 --- a/src/dataconnect/graphqlError.ts +++ b/src/dataconnect/graphqlError.ts @@ -1,5 +1,5 @@ import { GraphqlError } from "./types"; -const Table = require("cli-table"); +const Table = require("cli-table3"); export function prettify(err: GraphqlError): string { const message = err.message; @@ -17,6 +17,8 @@ export function prettifyWithWorkaround(errs: GraphqlError[]): string { const table = new Table({ head: ["Issue", "Workaround", "Reason"], style: { head: ["yellow"] }, + colWidths: [75, 75, 75], + wordWrap: true, }); for (const e of errs) { if (!e.extensions?.workarounds?.length) { @@ -25,9 +27,9 @@ export function prettifyWithWorkaround(errs: GraphqlError[]): string { 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]); } } } diff --git a/src/dataconnect/types.ts b/src/dataconnect/types.ts index 19c8f3d21cd..434bb65caa0 100644 --- a/src/dataconnect/types.ts +++ b/src/dataconnect/types.ts @@ -74,10 +74,9 @@ export interface Diff { 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 { From b95b23fcdd868406229705d6e29a7dcbfc7fd181 Mon Sep 17 00:00:00 2001 From: Rosalyn Tan Date: Mon, 3 Feb 2025 17:09:23 -0800 Subject: [PATCH 4/5] Make formatting fit a little better inside VSCode terminal. --- src/dataconnect/graphqlError.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/dataconnect/graphqlError.ts b/src/dataconnect/graphqlError.ts index dd55ab6ef74..9af09becd9f 100644 --- a/src/dataconnect/graphqlError.ts +++ b/src/dataconnect/graphqlError.ts @@ -17,7 +17,7 @@ export function prettifyWithWorkaround(errs: GraphqlError[]): string { const table = new Table({ head: ["Issue", "Workaround", "Reason"], style: { head: ["yellow"] }, - colWidths: [75, 75, 75], + colWidths: [50, 50, 50], wordWrap: true, }); for (const e of errs) { From 7d9f29635d3f5dac2d0ca762adf5ca236bb22583 Mon Sep 17 00:00:00 2001 From: Rosalyn Tan Date: Thu, 6 Feb 2025 10:47:22 -0800 Subject: [PATCH 5/5] Remove merge conflict markings. --- src/dataconnect/graphqlError.ts | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/dataconnect/graphqlError.ts b/src/dataconnect/graphqlError.ts index 405e778265f..5f48a892102 100644 --- a/src/dataconnect/graphqlError.ts +++ b/src/dataconnect/graphqlError.ts @@ -1,9 +1,5 @@ import { GraphqlError } from "./types"; -<<<<<<< HEAD -const Table = require("cli-table3"); -======= import * as Table from "cli-table3"; ->>>>>>> master export function prettify(err: GraphqlError): string { const message = err.message;