From baa730a433d150bb28fd6f934ad6d6c7b2e88bd1 Mon Sep 17 00:00:00 2001 From: HassanBahati Date: Tue, 13 Jan 2026 13:16:51 +0300 Subject: [PATCH 1/2] chore(firestore-bigquery-export): improve fs-bq-schema-views error message when projectIds are invalid --- .../scripts/gen-schema-view/src/index.ts | 24 +++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/firestore-bigquery-export/scripts/gen-schema-view/src/index.ts b/firestore-bigquery-export/scripts/gen-schema-view/src/index.ts index 81c382be1..40bc3fbcc 100644 --- a/firestore-bigquery-export/scripts/gen-schema-view/src/index.ts +++ b/firestore-bigquery-export/scripts/gen-schema-view/src/index.ts @@ -19,7 +19,7 @@ import firebase = require("firebase-admin"); import { FirestoreBigQuerySchemaViewFactory, FirestoreSchema } from "./schema"; import { readSchemas } from "./schema-loader-utils"; -import { parseConfig } from "./config"; +import { parseConfig, CliConfig } from "./config"; import { generateSchemaFilesWithGemini } from "./schema/genkit"; export async function run(): Promise { @@ -72,12 +72,32 @@ export async function run(): Promise { } if (process.env.NODE_ENV !== "test") { - run() + let config: CliConfig | null = null; + + parseConfig() + .then((parsedConfig) => { + config = parsedConfig; + return run(); + }) .then((result) => { console.log("done."); process.exit(); }) .catch((error) => { + if (config) { + const errorMessage = error.message || error.errors?.[0]?.message; + if ( + errorMessage?.includes("ProjectId must be non-empty") || + errorMessage?.includes("Cannot parse as CloudRegion") + ) { + const improvedMessage = `The BigQuery Project ID '${config.bigQueryProjectId}' is not valid. Please verify that the project ID is correct and that you have access to it.`; + error.message = improvedMessage; + if (error.errors?.[0]) { + error.errors[0].message = improvedMessage; + } + } + } + console.log(JSON.stringify(error)); console.error(error.message); process.exit(); From cb677d6b1b60152c5a3cd413de2630bee9f80adf Mon Sep 17 00:00:00 2001 From: Izaak Gough Date: Thu, 23 Apr 2026 15:47:59 +0100 Subject: [PATCH 2/2] refactor: add optional config to run --- .../scripts/gen-schema-view/src/index.ts | 36 ++++++++++--------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/firestore-bigquery-export/scripts/gen-schema-view/src/index.ts b/firestore-bigquery-export/scripts/gen-schema-view/src/index.ts index 40bc3fbcc..980e1f45b 100644 --- a/firestore-bigquery-export/scripts/gen-schema-view/src/index.ts +++ b/firestore-bigquery-export/scripts/gen-schema-view/src/index.ts @@ -22,30 +22,32 @@ import { readSchemas } from "./schema-loader-utils"; import { parseConfig, CliConfig } from "./config"; import { generateSchemaFilesWithGemini } from "./schema/genkit"; -export async function run(): Promise { - const config = await parseConfig(); +export async function run(config?: CliConfig): Promise { + const cliConfig = config ?? (await parseConfig()); - process.env.PROJECT_ID = config.projectId; - process.env.GOOGLE_CLOUD_PROJECT = config.bigQueryProjectId; + process.env.PROJECT_ID = cliConfig.projectId; + process.env.GOOGLE_CLOUD_PROJECT = cliConfig.bigQueryProjectId; if (!firebase.apps.length) { firebase.initializeApp({ credential: firebase.credential.applicationDefault(), - databaseURL: `https://${config.projectId}.firebaseio.com`, + databaseURL: `https://${cliConfig.projectId}.firebaseio.com`, }); } const viewFactory = new FirestoreBigQuerySchemaViewFactory( - config.bigQueryProjectId + cliConfig.bigQueryProjectId ); // Generate schema files using Gemini if enabled // Otherwise, read schema files from the filesystem - let schemas = config.schemas; - if (config.useGemini) { + let schemas = cliConfig.schemas; + if (cliConfig.useGemini) { try { - await generateSchemaFilesWithGemini(config); - schemas = readSchemas([`./schemas/${config.geminiSchemaFileName}.json`]); + await generateSchemaFilesWithGemini(cliConfig); + schemas = readSchemas([ + `./schemas/${cliConfig.geminiSchemaFileName}.json`, + ]); console.log("Schema file generated successfully."); } catch (error) { @@ -53,7 +55,7 @@ export async function run(): Promise { throw error; } } else { - if (Object.keys(config.schemas).length === 0) { + if (Object.keys(cliConfig.schemas).length === 0) { console.log(`No schema files found!`); } } @@ -61,8 +63,8 @@ export async function run(): Promise { // Initialize schema views for (const name in schemas) { await viewFactory.initializeSchemaViewResources( - config.datasetId, - config.tableNamePrefix, + cliConfig.datasetId, + cliConfig.tableNamePrefix, name, schemas[name] ); @@ -77,11 +79,11 @@ if (process.env.NODE_ENV !== "test") { parseConfig() .then((parsedConfig) => { config = parsedConfig; - return run(); + return run(parsedConfig); }) - .then((result) => { + .then(() => { console.log("done."); - process.exit(); + process.exit(0); }) .catch((error) => { if (config) { @@ -100,6 +102,6 @@ if (process.env.NODE_ENV !== "test") { console.log(JSON.stringify(error)); console.error(error.message); - process.exit(); + process.exit(1); }); }