Skip to content

Commit a014595

Browse files
authored
Merge pull request #343 from Dexterp37/cli_return
Bug 1712048 - Report the correct exit code when failing in the CLI
2 parents 0a8314f + 321a255 commit a014595

File tree

4 files changed

+37
-30
lines changed

4 files changed

+37
-30
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
[Full changelog](https://github.com/mozilla/glean.js/compare/v0.13.0...v0.14.0)
88

99
* [#313](https://github.com/mozilla/glean.js/pull/313): Send Glean.js version and platform information on X-Telemetry-Agent header instead of User-Agent header.
10+
* [#343](https://github.com/mozilla/glean.js/pull/343): BUGFIX: Report the correct failure exit code when the Glean command line tool fails.
11+
1012
# v0.13.0 (2021-05-18)
1113

1214
[Full changelog](https://github.com/mozilla/glean.js/compare/v0.12.0...v0.13.0)

glean/src/cli.ts

Lines changed: 29 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ async function setup(projectRoot: string) {
165165
console.log(`Using Glean virtual environment at ${venvRoot}`);
166166
} else if (!await createPythonVenv(venvRoot)){
167167
console.error(`Failed to create a Glean virtual environment at ${venvRoot}`);
168+
process.exit(1);
168169
}
169170
}
170171

@@ -189,33 +190,10 @@ async function runGlean(projectRoot: string, parserArgs: string[]) {
189190

190191
if (err) {
191192
console.error(`${stderr}`);
193+
process.exit(1);
192194
}
193195
}
194196

195-
/**
196-
* Runs the command.
197-
*
198-
* @param args the arguments passed to this process.
199-
*/
200-
async function run(args: string[]) {
201-
if (args.length < 3) {
202-
throw new Error("Not enough arguments. Please refer to https://mozilla.github.io/glean_parser/readme.html");
203-
}
204-
205-
const projectRoot = process.cwd();
206-
try {
207-
await setup(projectRoot);
208-
} catch (err) {
209-
console.error("Failed to setup the Glean build environment", err);
210-
}
211-
212-
await runGlean(projectRoot, args.slice(2));
213-
}
214-
215-
run(argv).catch(e => {
216-
console.error("There was an error running Glean", e);
217-
});
218-
219197
/**
220198
* Returns a spinner
221199
*
@@ -239,3 +217,30 @@ function stopSpinner(spinner: NodeJS.Timeout) {
239217
process.stdout.write(" \r");
240218
clearInterval(spinner);
241219
}
220+
221+
/**
222+
* Runs the command.
223+
*
224+
* @param args the arguments passed to this process.
225+
*/
226+
async function run(args: string[]) {
227+
if (args.length < 3) {
228+
throw new Error("Not enough arguments. Please refer to https://mozilla.github.io/glean_parser/readme.html");
229+
}
230+
231+
const projectRoot = process.cwd();
232+
try {
233+
await setup(projectRoot);
234+
} catch (err) {
235+
console.error("Failed to setup the Glean build environment", err);
236+
process.exit(1);
237+
}
238+
239+
await runGlean(projectRoot, args.slice(2));
240+
}
241+
242+
// For discoverability, try to leave this function as the last one on this file.
243+
run(argv).catch(e => {
244+
console.error("There was an error running Glean", e);
245+
process.exit(1);
246+
});

samples/web-extension/javascript/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,14 @@ Running the example requires Python 3.
1717
npm link
1818
```
1919

20-
2. Link the `@mozilla/glean` package to this sample web extension. On this `web-extension` folder run:
20+
2. Link the `@mozilla/glean` package to this sample web extension. On this `web-extension/javascript` folder run:
2121

2222
```bash
2323
npm install
2424
npm link @mozilla/glean
2525
```
2626

27-
3. Build this sample. On this `web-extension` folder run:
27+
3. Build this sample. On this `web-extension/javascript` folder run:
2828

2929
```bash
3030
npm run build
@@ -44,6 +44,6 @@ npm run build
4444
- **Chromium-based browsers**
4545
1. Go to [chrome://extensions](chrome://extensions);
4646
2. Click on `Load unpacked`;
47-
3. Choose this `web-extension` folder;
47+
3. Choose this `web-extension/javascript` folder;
4848
4. Click on `background page`;
4949
5. Try clicking on the little Glean logo that should have been added to your browsers toolbar.

samples/web-extension/typescript/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,14 @@ Running the example requires Python 3.
1717
npm link
1818
```
1919

20-
2. Link the `@mozilla/glean` package to this sample web extension. On this `web-extension` folder run:
20+
2. Link the `@mozilla/glean` package to this sample web extension. In this `web-extension/typescript` folder run:
2121

2222
```bash
2323
npm install
2424
npm link @mozilla/glean
2525
```
2626

27-
3. Build this sample. On this `web-extension` folder run:
27+
3. Build this sample. On this `web-extension/typescript` folder run:
2828

2929
```bash
3030
npm run build
@@ -44,6 +44,6 @@ npm run build
4444
- **Chromium-based browsers**
4545
1. Go to [chrome://extensions](chrome://extensions);
4646
2. Click on `Load unpacked`;
47-
3. Choose this `web-extension` folder;
47+
3. Choose this `web-extension/typescript` folder;
4848
4. Click on `background page`;
4949
5. Try clicking on the little Glean logo that should have been added to your browsers toolbar.

0 commit comments

Comments
 (0)