Skip to content

Commit 678a833

Browse files
authored
Merge pull request #214 from Dexterp37/cli_err
Bug 1699394 - Improve the error reporting of the Glean cli tool
2 parents 9ea16c2 + 8f9df16 commit 678a833

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

glean/src/cli.ts

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,6 @@ import * as path from "path";
1010
import { argv, platform } from "process";
1111
import { promisify } from "util";
1212

13-
// Define an async/await version of "exec".
14-
const execAsync = promisify(exec.exec);
15-
1613
// The name of the directory which will contain the Python virtual environment
1714
// used to run the glean-parser.
1815
const VIRTUAL_ENVIRONMENT_DIR = ".venv";
@@ -140,10 +137,12 @@ async function createPythonVenv(venvPath: string): Promise<boolean> {
140137
const venvCmd = `${getSystemPythonBinName()} -m venv ${VIRTUAL_ENVIRONMENT_DIR}`;
141138

142139
for (const cmd of [venvCmd, pipCmd]) {
143-
try {
144-
await execAsync(cmd);
145-
} catch (e) {
146-
console.error(e);
140+
const {err, stdout, stderr} = await new Promise<{err: exec.ExecException | null, stdout: string, stderr: string}>(resolve => {
141+
exec.exec(cmd, (err, stdout, stderr) => resolve({err, stdout, stderr}));
142+
});
143+
144+
if (err) {
145+
console.error(`${stdout}\n${stderr}`);
147146
return false;
148147
}
149148
}
@@ -178,10 +177,13 @@ async function runGlean(projectRoot: string, parserArgs: string[]) {
178177
const venvRoot = path.join(projectRoot, VIRTUAL_ENVIRONMENT_DIR);
179178
const pythonBin = path.join(getPythonVenvBinariesPath(venvRoot), getSystemPythonBinName());
180179
const cmd = `${pythonBin} -c "${PYTHON_SCRIPT}" online glean_parser ${GLEAN_PARSER_VERSION} ${parserArgs.join(" ")}`;
181-
try {
182-
await execAsync(cmd);
183-
} catch (e) {
184-
console.error(e);
180+
181+
const {err, stdout, stderr} = await new Promise<{err: exec.ExecException | null, stdout: string, stderr: string}>(resolve => {
182+
exec.exec(cmd, (err, stdout, stderr) => resolve({err, stdout, stderr}));
183+
});
184+
185+
if (err) {
186+
console.error(`${stdout}\n${stderr}`);
185187
}
186188
}
187189

0 commit comments

Comments
 (0)