Skip to content

Commit

Permalink
Better error message when Rosetta is missing (#8030)
Browse files Browse the repository at this point in the history
  • Loading branch information
joehan authored Dec 4, 2024
1 parent 9ad8df3 commit 7f1c599
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 3 deletions.
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 * as path from "path";

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 @@ -83,14 +89,14 @@ export class DataConnectEmulator implements EmulatorInstance {
} catch (err: any) {
this.logger.log("DEBUG", `'fdc build' failed with error: ${err.message}`);
}

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 Down Expand Up @@ -211,7 +217,13 @@ export class DataConnectEmulator implements EmulatorInstance {
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 @@ export class DataConnectEmulator implements EmulatorInstance {
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"
);
}

0 comments on commit 7f1c599

Please sign in to comment.