Skip to content
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
Expand Up @@ -3,6 +3,7 @@
- Fixed an issue where `firebase` would error out instead of displaying help text.
- Fixed an issue where `firebase init genkit` would error on Windows machines.
- Fixed an issue where emulator returned error when emulating alerts functions written in python (#8019)
- Better error message for emulator binary architecture incompatibility on MacOS (#7995).
- Deprecated `emulators.apphosting.startCommandOverride`. Please use `emulators.apphosting.startCommand` instead.
- Updated `superstatic` to `9.1.0` in package.json.
- Updated the Firebase Data Connect local toolkit to v1.7.4, which includes a fix for an issue that caused duplicate installations of the Firebase JS SDK. (#8028)
25 changes: 22 additions & 3 deletions src/emulator/dataconnectEmulator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,13 @@

import { dataConnectLocalConnString } from "../api";
import { Constants } from "./constants";
import { getPID, start, stop, downloadIfNecessary } from "./downloadableEmulators";
import {
getPID,
start,
stop,
downloadIfNecessary,
isIncomaptibleArchError,
} from "./downloadableEmulators";
import { EmulatorInfo, EmulatorInstance, Emulators, ListenSpec } from "./types";
import { FirebaseError } from "../error";
import { EmulatorLogger } from "./emulatorLogger";
Expand Down Expand Up @@ -51,11 +57,11 @@

export class DataConnectEmulator implements EmulatorInstance {
private emulatorClient: DataConnectEmulatorClient;
private usingExistingEmulator: boolean = false;

Check warning on line 60 in src/emulator/dataconnectEmulator.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Type boolean trivially inferred from a boolean literal, remove type annotation
private postgresServer: PostgresServer | undefined;

constructor(private args: DataConnectEmulatorArgs) {
this.emulatorClient = new DataConnectEmulatorClient();

Check warning on line 64 in src/emulator/dataconnectEmulator.ts

View workflow job for this annotation

GitHub Actions / lint (20)

'DataConnectEmulatorClient' was used before it was defined
}
private logger = EmulatorLogger.forEmulator(Emulators.DATACONNECT);

Expand All @@ -80,17 +86,17 @@
);
}
}
} catch (err: any) {

Check warning on line 89 in src/emulator/dataconnectEmulator.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unexpected any. Specify a different type
this.logger.log("DEBUG", `'fdc build' failed with error: ${err.message}`);

Check warning on line 90 in src/emulator/dataconnectEmulator.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Invalid type "any" of template literal expression

Check warning on line 90 in src/emulator/dataconnectEmulator.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unsafe member access .message on an `any` value
}

await start(Emulators.DATACONNECT, {
auto_download: this.args.auto_download,
listen: listenSpecsToString(this.args.listen),
config_dir: resolvedConfigDir,
enable_output_schema_extensions: this.args.enable_output_schema_extensions,
enable_output_generated_sdk: this.args.enable_output_generated_sdk,
});

this.usingExistingEmulator = false;
if (this.args.autoconnectToPostgres) {
const info = await load(this.args.projectId, this.args.config, this.args.configDir);
Expand All @@ -106,22 +112,22 @@
`FIREBASE_DATACONNECT_POSTGRESQL_STRING is set to ${clc.bold(connStr)} - using that instead of starting a new database`,
);
} else if (pgHost && pgPort) {
const dataDirectory = this.args.config.get("emulators.dataconnect.dataDir");

Check warning on line 115 in src/emulator/dataconnectEmulator.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unsafe assignment of an `any` value
const postgresDumpPath = this.args.importPath
? path.join(this.args.importPath, "postgres.tar.gz")
: undefined;
this.postgresServer = new PostgresServer(dbId, "postgres", dataDirectory, postgresDumpPath);

Check warning on line 119 in src/emulator/dataconnectEmulator.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unsafe argument of type `any` assigned to a parameter of type `string | undefined`
const server = await this.postgresServer.createPGServer(pgHost, pgPort);
const connectableHost = connectableHostname(pgHost);
connStr = `postgres://${connectableHost}:${pgPort}/${dbId}?sslmode=disable`;
server.on("error", (err: any) => {

Check warning on line 123 in src/emulator/dataconnectEmulator.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unexpected any. Specify a different type
if (err instanceof FirebaseError) {
this.logger.logLabeled("ERROR", "Data Connect", `${err}`);

Check warning on line 125 in src/emulator/dataconnectEmulator.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Invalid type "FirebaseError" of template literal expression
} else {
this.logger.logLabeled(
"ERROR",
"dataconnect",
`Postgres threw an unexpected error, shutting down the Data Connect emulator: ${err}`,

Check warning on line 130 in src/emulator/dataconnectEmulator.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Invalid type "any" of template literal expression
);
}
void cleanShutdown();
Expand Down Expand Up @@ -211,7 +217,13 @@
cmd.push("--watch");
}
const res = childProcess.spawnSync(commandInfo.binary, cmd, { encoding: "utf-8" });

if (isIncomaptibleArchError(res.error)) {
throw new FirebaseError(
`Unknown system error when running the Data Connect toolkit. ` +
`You may be able to fix this by installing Rosetta: ` +
`softwareupdate --install-rosetta`,
);
}
logger.info(res.stderr);
if (res.error) {
throw new FirebaseError(`Error starting up Data Connect generate: ${res.error.message}`, {
Expand All @@ -231,6 +243,13 @@
const cmd = ["--logtostderr", "-v=2", "build", `--config_dir=${args.configDir}`];

const res = childProcess.spawnSync(commandInfo.binary, cmd, { encoding: "utf-8" });
if (isIncomaptibleArchError(res.error)) {
throw new FirebaseError(
`Unkown system error when running the Data Connect toolkit. ` +
`You may be able to fix this by installing Rosetta: ` +
`softwareupdate --install-rosetta`,
);
}
if (res.error) {
throw new FirebaseError(`Error starting up Data Connect build: ${res.error.message}`, {
original: res.error,
Expand Down
17 changes: 17 additions & 0 deletions src/emulator/downloadableEmulators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,14 @@ async function _runBinary(
emulator.name,
`Could not spawn child process for emulator, check that java is installed and on your $PATH.`,
);
} else if (isIncomaptibleArchError(e)) {
logger.logLabeled(
"WARN",
emulator.name,
`Unknown system error when starting emulator binary. ` +
`You may be able to fix this by installing Rosetta: ` +
`softwareupdate --install-rosetta`,
);
}
_fatal(emulator.name, e);
}
Expand Down Expand Up @@ -645,3 +653,12 @@ export async function start(
);
return _runBinary(emulator, command, extraEnv);
}

export function isIncomaptibleArchError(err: unknown): boolean {
const hasMessage = (e: any): e is { message: string } => !!e.message;
return (
hasMessage(err) &&
/Unknown system error/.test(err.message ?? "") &&
process.platform === "darwin"
);
}
Loading