Skip to content

Commit 073a953

Browse files
fredzqmgoogle-labs-jules[bot]gemini-code-assist[bot]joehan
authored
fix: use cross-spawn to avoid exec format errors when creating dataconnect apps (#10616)
* fix: use cross-spawn to avoid exec format errors when creating dataconnect apps Replaces the native child_process spawn with cross-spawn and removes the `shell: true` option in `src/init/features/dataconnect/create_app.ts`. This ensures that the `dataconnect` CLI successfully executes commands like `npm` on Windows and other OSes without encountering `ENOEXEC` format errors. Co-authored-by: fredzqm <9068391+fredzqm@users.noreply.github.com> * fix: use cross-spawn to avoid exec format errors when creating dataconnect apps Replaces the native child_process spawn with cross-spawn and removes the `shell: true` option in `src/init/features/dataconnect/create_app.ts`. This ensures that the `dataconnect` CLI successfully executes commands like `npm` on Windows and other OSes without encountering `ENOEXEC` format errors. Also updates CHANGELOG.md. Co-authored-by: fredzqm <9068391+fredzqm@users.noreply.github.com> * Apply suggestion from @gemini-code-assist[bot] Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> * improve error logging * Update CHANGELOG.md * fix: resolve lint and formatting issues in dataconnect app creation * revert: remove test-init ignores from .eslintignore and .gitignore --------- Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com> Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> Co-authored-by: Joe Hanley <joehanley@google.com>
1 parent 7657d15 commit 073a953

3 files changed

Lines changed: 10 additions & 9 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1+
- Fixes `firebase init dataconnect` failing with `ENOEXEC` when creating a new template app on some operating systems. (#10616)
12
- Support setting the Google Cloud Storage (GCS) test results bucket in `apptesting:execute` and `appdistribution:distribute`

src/init/features/dataconnect/create_app.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { spawn } from "child_process";
1+
import * as spawn from "cross-spawn";
22
import * as clc from "colorette";
33
import { logLabeledBullet } from "../../../utils";
44

@@ -40,8 +40,6 @@ async function executeCommand(command: string, args: string[]): Promise<void> {
4040
const childProcess = spawn(command, args, {
4141
// 'inherit' pipes stdin, stdout, and stderr to the parent process
4242
stdio: "inherit",
43-
// Runs the command in a shell, which allows for shell syntax like pipes, etc.
44-
shell: true,
4543
});
4644

4745
childProcess.on("close", (code) => {
@@ -50,7 +48,7 @@ async function executeCommand(command: string, args: string[]): Promise<void> {
5048
resolve();
5149
} else {
5250
// Command failed
53-
reject(new Error(`Command failed with exit code ${code}`));
51+
reject(new Error(`Command failed with exit code ${code ?? "null"}`));
5452
}
5553
});
5654

src/init/features/dataconnect/sdk.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import {
1919
SwiftSDK,
2020
} from "../../../dataconnect/types";
2121
import * as experiments from "../../../experiments";
22-
import { FirebaseError } from "../../../error";
22+
import { FirebaseError, getErrMsg, getErrStack } from "../../../error";
2323
import { isArray } from "lodash";
2424
import {
2525
logBullet,
@@ -100,8 +100,10 @@ export async function askQuestions(
100100
break;
101101
}
102102
} catch (err: unknown) {
103-
// The detailed error message are already piped into stderr. No need to repeat here.
104-
logLabeledError("dataconnect", `Failed to create a ${choice} app template`);
103+
logLabeledError(
104+
"dataconnect",
105+
`Failed to create a ${choice} app template: ${getErrStack(err)}`,
106+
);
105107
}
106108
}
107109

@@ -279,8 +281,8 @@ async function actuateWithInfo(setup: Setup, config: Config, info: SdkRequiredIn
279281
configDir: connectorInfo.directory,
280282
account,
281283
});
282-
} catch (e: any) {
283-
logLabeledError("dataconnect", `Failed to generate SQL Connect SDKs\n${e?.message}`);
284+
} catch (e: unknown) {
285+
logLabeledError("dataconnect", `Failed to generate SQL Connect SDKs\n${getErrMsg(e)}`);
284286
}
285287

286288
logLabeledSuccess(

0 commit comments

Comments
 (0)