Skip to content

Commit 3f27bd8

Browse files
authored
Improve logging when emulators are not starting (#3021)
1 parent f03c486 commit 3f27bd8

File tree

4 files changed

+22
-9
lines changed

4 files changed

+22
-9
lines changed

CHANGELOG.md

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1 @@
1-
- Add warning when a developer is using yarn@2 PnP (#2198).
2-
- Fixes incorrect URLs reported inside emulated HTTPS functions (#1862).
3-
- Updates underlying timeout handler when proxying through the Hosting emulator.
4-
- Adds support for installing [experimental extensions](https://github.com/FirebaseExtended/experimental-extensions) (#2830)
1+
- Improves logging for `emulators:start` and `emulators:exec` (#3020).

src/commands/emulators-start.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ module.exports = new Command("emulators:start")
4040
reservedPorts.push(info.port);
4141
}
4242
}
43+
const reservedPortsString = reservedPorts.length > 0 ? reservedPorts.join(", ") : "None";
44+
4345
const uiInfo = EmulatorRegistry.getInfo(Emulators.UI);
4446
const hubInfo = EmulatorRegistry.getInfo(Emulators.HUB);
4547
const uiUrl = uiInfo ? `http://${EmulatorRegistry.getInfoHostString(uiInfo)}` : "unknown";
@@ -97,7 +99,7 @@ ${
9799
? clc.blackBright(" Emulator Hub running at ") + EmulatorRegistry.getInfoHostString(hubInfo)
98100
: clc.blackBright(" Emulator Hub not running.")
99101
}
100-
${clc.blackBright(" Other reserved ports:")} ${reservedPorts.join(", ")}
102+
${clc.blackBright(" Other reserved ports:")} ${reservedPortsString}
101103
102104
Issues? Report them at ${stylizeLink(
103105
"https://github.com/firebase/firebase-tools/issues"

src/emulator/commandUtils.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -405,8 +405,8 @@ export async function emulatorExec(script: string, options: any) {
405405
}
406406
let exitCode = 0;
407407
try {
408-
const excludeUi = !options.ui;
409-
await controller.startAll(options, excludeUi);
408+
const showUI = !!options.ui;
409+
await controller.startAll(options, showUI);
410410
exitCode = await runScript(script, extraEnv);
411411
await onExit(options);
412412
} finally {

src/emulator/controller.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ function findExportMetadata(importPath: string): ExportMetadata | undefined {
291291
}
292292
}
293293

294-
export async function startAll(options: any, noUi: boolean = false): Promise<void> {
294+
export async function startAll(options: any, showUI: boolean = true): Promise<void> {
295295
// Emulators config is specified in firebase.json as:
296296
// "emulators": {
297297
// "firestore": {
@@ -309,6 +309,12 @@ export async function startAll(options: any, noUi: boolean = false): Promise<voi
309309

310310
const projectId: string | undefined = getProjectId(options, true);
311311

312+
if (targets.length === 0) {
313+
throw new FirebaseError(
314+
`No emulators to start, run ${clc.bold("firebase init emulators")} to get started.`
315+
);
316+
}
317+
312318
EmulatorLogger.forEmulator(Emulators.HUB).logLabeled(
313319
"BULLET",
314320
"emulators",
@@ -588,7 +594,15 @@ export async function startAll(options: any, noUi: boolean = false): Promise<voi
588594
await startEmulator(hostingEmulator);
589595
}
590596

591-
if (!noUi && shouldStart(options, Emulators.UI)) {
597+
if (showUI && !shouldStart(options, Emulators.UI)) {
598+
EmulatorLogger.forEmulator(Emulators.HUB).logLabeled(
599+
"WARN",
600+
"emulators",
601+
"The Emulator UI requires a project ID to start. Configure your default project with 'firebase use' or pass the ---project flag."
602+
);
603+
}
604+
605+
if (showUI && shouldStart(options, Emulators.UI)) {
592606
const loggingAddr = await getAndCheckAddress(Emulators.LOGGING, options);
593607
const loggingEmulator = new LoggingEmulator({
594608
host: loggingAddr.host,

0 commit comments

Comments
 (0)