Skip to content
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

Better error when incorrect project ID is used. #7827

Merged
merged 4 commits into from
Oct 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
- Fixed Flutter web apps that might require the --no-tree-shake-icons flag in order to build. (#7724)
- Fixed an issue where the Extensions emulator would fail silently if started with a non-existant project without the `demo-` prefix. (#7779)
18 changes: 15 additions & 3 deletions src/emulator/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,20 +69,20 @@

/**
* Exports emulator data on clean exit (SIGINT or process end)
* @param options

Check warning on line 72 in src/emulator/controller.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Missing JSDoc @param "options" description
*/
export async function exportOnExit(options: any) {

Check warning on line 74 in src/emulator/controller.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Missing return type on function

Check warning on line 74 in src/emulator/controller.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unexpected any. Specify a different type
const exportOnExitDir = options.exportOnExit;

Check warning on line 75 in src/emulator/controller.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unsafe assignment of an `any` value

Check warning on line 75 in src/emulator/controller.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unsafe member access .exportOnExit on an `any` value
if (exportOnExitDir) {
try {
utils.logBullet(
`Automatically exporting data using ${FLAG_EXPORT_ON_EXIT_NAME} "${exportOnExitDir}" ` +

Check warning on line 79 in src/emulator/controller.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Invalid type "any" of template literal expression
"please wait for the export to finish...",
);
await exportEmulatorData(exportOnExitDir, options, /* initiatedBy= */ "exit");

Check warning on line 82 in src/emulator/controller.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unsafe argument of type `any` assigned to a parameter of type `string`
} catch (e: any) {

Check warning on line 83 in src/emulator/controller.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unexpected any. Specify a different type
utils.logWarning(e);

Check warning on line 84 in src/emulator/controller.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unsafe argument of type `any` assigned to a parameter of type `string`
utils.logWarning(`Automatic export to "${exportOnExitDir}" failed, going to exit now...`);

Check warning on line 85 in src/emulator/controller.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Invalid type "any" of template literal expression
}
}
}
Expand Down Expand Up @@ -352,9 +352,21 @@
// the Functions emulator needs to start.
let extensionEmulator: ExtensionsEmulator | undefined = undefined;
if (shouldStart(options, Emulators.EXTENSIONS)) {
const projectNumber = isDemoProject
? Constants.FAKE_PROJECT_NUMBER
: await needProjectNumber(options);
let projectNumber = Constants.FAKE_PROJECT_NUMBER;
if (!isDemoProject) {
try {
projectNumber = await needProjectNumber(options);
} catch (err: any) {
EmulatorLogger.forEmulator(Emulators.EXTENSIONS).logLabeled(
"ERROR",
Emulators.EXTENSIONS,
`Unable to look up project number for ${options.project}.\n` +
" If this is a real project, ensure that you are logged in and have access to it.\n" +
" If this is a fake project, please use a project ID starting with 'demo-' to skip production calls.\n" +
" Continuing with a fake project number - secrets and other features that require production access may behave unexpectedly.",
);
}
}
const aliases = getAliases(options, projectId);
extensionEmulator = new ExtensionsEmulator({
options,
Expand Down
21 changes: 16 additions & 5 deletions src/extensions/extensionsHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import * as refs from "./refs";
import { EXTENSIONS_SPEC_FILE, readFile, getLocalExtensionSpec } from "./localHelper";
import { confirm, promptOnce } from "../prompt";
import { logger } from "../logger";
import { envOverride } from "../utils";
import { envOverride, logLabeledError } from "../utils";
import { getLocalChangelog } from "./change-log";
import { getProjectNumber } from "../getProjectNumber";
import { Constants } from "../emulator/constants";
Expand Down Expand Up @@ -122,10 +122,21 @@ export async function getFirebaseProjectParams(
const body = emulatorMode
? await getProjectAdminSdkConfigOrCached(projectId)
: await getFirebaseConfig({ project: projectId });
const projectNumber =
emulatorMode && Constants.isDemoProject(projectId)
? Constants.FAKE_PROJECT_NUMBER
: await getProjectNumber({ projectId });

let projectNumber = Constants.FAKE_PROJECT_NUMBER;
if (!Constants.isDemoProject(projectId)) {
try {
projectNumber = await getProjectNumber({ projectId });
} catch (err: any) {
logLabeledError(
"extensions",
`Unable to look up project number for ${projectId}.\n` +
" If this is a real project, ensure that you are logged in and have access to it.\n" +
" If this is a fake project, please use a project ID starting with 'demo-' to skip production calls.\n" +
" Continuing with a fake project number - secrets and other features that require production access may behave unexpectedly.",
);
}
}
const databaseURL = body?.databaseURL ?? `https://${projectId}.firebaseio.com`;
const storageBucket = body?.storageBucket ?? `${projectId}.appspot.com`;
// This env variable is needed for parameter-less initialization of firebase-admin
Expand Down
Loading