Skip to content

Commit bd678cf

Browse files
chore(js): Remove live = 'rejectOnError' option (#2971)
### Description We added the `live = 'rejectOnError'` option in #2605 with the intention to make the behavior provided by setting `live = 'rejectOnError'` the default behavior of setting `live = true` in the next major. ### Issues - Resolves #2606 - Resolves [CLI-138](https://linear.app/getsentry/issue/CLI-138/v3-fix-js-interface-execute-promise-resolve-values)
1 parent 002c166 commit bd678cf

File tree

7 files changed

+36
-74
lines changed

7 files changed

+36
-74
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ we should rename this section to "Unreleased" -->
2020
- `api_key` configuration file field
2121
- `apiKey` option in the JavaScript API
2222
- Removed the `upload-proguard` subcommand's `--app-id`, `--version`, `--version-code`, `--android-manifest`, and `--platform` arguments ([#2876](https://github.com/getsentry/sentry-cli/pull/2876), [#2940](https://github.com/getsentry/sentry-cli/pull/2940), [#2948](https://github.com/getsentry/sentry-cli/pull/2948)). Users using these arguments should stop using them, as they are unnecessary. The information passed to these arguments is no longer visible in Sentry.
23+
- In the JS API, the `SentryCli.execute` method's `live` parameter now only takes boolean values ([#2971](https://github.com/getsentry/sentry-cli/pull/2971)). Setting `live` to `true` now behaves like `'rejectOnError'` did previously, with a zero exit status resolving the returned promise with `"success (live mode)"` and a non-zero status rejecting the promise with an error message.
24+
- In the JS API, the `option` parameter to `Releases.uploadSourceMaps` no longer takes a `live` property ([#2971](https://github.com/getsentry/sentry-cli/pull/2971)). We now always execute the command with `live` set to `true`.
2325

2426
### Improvements
2527

lib/__tests__/helper.test.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,27 @@ describe('SentryCli helper', () => {
2828
expect(output.trim()).toBe('sentry-cli DEV');
2929
});
3030

31-
test('execute with live=true resolves without output', async () => {
31+
test('execute with live=true resolves on success', async () => {
3232
// TODO (v3): This should resolve with a string, not undefined/void
3333
const result = await helper.execute(['--version'], true);
34-
expect(result).toBeUndefined();
34+
expect(result).toBe('success (live mode)');
35+
});
36+
37+
test('execute with live=true rejects on failure', async () => {
38+
await expect(helper.execute(['fail'], true)).rejects.toThrow(
39+
'Command fail failed with exit code 1'
40+
);
3541
});
3642

43+
// live=rejectOnError is not supported per the type declarations, but we should still aim
44+
// to support it for backwards compatibility.
3745
test('execute with live=rejectOnError resolves on success', async () => {
3846
const result = await helper.execute(['--version'], 'rejectOnError');
3947
expect(result).toBe('success (live mode)');
4048
});
4149

50+
// live=rejectOnError is not supported per the type declarations, but we should still aim
51+
// to support it for backwards compatibility.
4252
test('execute with live=rejectOnError rejects on failure', async () => {
4353
await expect(helper.execute(['fail'], 'rejectOnError')).rejects.toThrow(
4454
'Command fail failed with exit code 1'

lib/helper.js

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -281,11 +281,10 @@ function getPath() {
281281
* expect(output.trim()).toBe('sentry-cli x.y.z');
282282
*
283283
* @param {string[]} args Command line arguments passed to `sentry-cli`.
284-
* @param {boolean | 'rejectOnError'} live can be set to:
285-
* - `true` to inherit stdio to display `sentry-cli` output directly.
286-
* - `false` to not inherit stdio and return the output as a string.
287-
* - `'rejectOnError'` to inherit stdio and reject the promise if the command
284+
* @param {boolean} live can be set to:
285+
* - `true` to inherit stdio and reject the promise if the command
288286
* exits with a non-zero exit code.
287+
* - `false` to not inherit stdio and return the output as a string.
289288
* @param {boolean} silent Disable stdout for silents build (CI/Webpack Stats, ...)
290289
* @param {string} [configFile] Relative or absolute path to the configuration file.
291290
* @param {import('./index').SentryCliOptions} [config] More configuration to pass to the CLI
@@ -325,26 +324,18 @@ async function execute(args, live, silent, configFile, config = {}) {
325324
}
326325

327326
return new Promise((resolve, reject) => {
328-
if (live === true || live === 'rejectOnError') {
327+
if (live) {
329328
const output = silent ? 'ignore' : 'inherit';
330329
const pid = childProcess.spawn(getPath(), args, {
331330
env,
332331
// stdin, stdout, stderr
333332
stdio: ['ignore', output, output],
334333
});
335334
pid.on('exit', (exitCode) => {
336-
if (live === 'rejectOnError') {
337-
if (exitCode === 0) {
338-
resolve('success (live mode)');
339-
}
340-
reject(new Error(`Command ${args.join(' ')} failed with exit code ${exitCode}`));
335+
if (exitCode === 0) {
336+
resolve('success (live mode)');
341337
}
342-
// According to the type definition, resolving with void is not allowed.
343-
// However, for backwards compatibility, we resolve void here to
344-
// avoid a behaviour-breaking change.
345-
// TODO (v3): Clean this up and always resolve a string (or change the type definition)
346-
// @ts-expect-error - see comment above
347-
resolve();
338+
reject(new Error(`Command ${args.join(' ')} failed with exit code ${exitCode}`));
348339
});
349340
} else {
350341
childProcess.execFile(getPath(), args, { env }, (err, stdout) => {

lib/index.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,10 @@ class SentryCli {
6868
/**
6969
* See {helper.execute} docs.
7070
* @param {string[]} args Command line arguments passed to `sentry-cli`.
71-
* @param {boolean | 'rejectOnError'} live can be set to:
72-
* - `true` to inherit stdio to display `sentry-cli` output directly.
73-
* - `false` to not inherit stdio and return the output as a string.
74-
* - `'rejectOnError'` to inherit stdio and reject the promise if the command
71+
* @param {boolean} live can be set to:
72+
* - `true` to inherit stdio and reject the promise if the command
7573
* exits with a non-zero exit code.
74+
* - `false` to not inherit stdio and return the output as a string.
7675
* @returns {Promise<string>} A promise that resolves to the standard output.
7776
*/
7877
execute(args, live) {

lib/releases/__tests__/index.test.js

Lines changed: 5 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@ describe('SentryCli releases', () => {
77
test('call sentry-cli releases propose-version', () => {
88
expect.assertions(1);
99
const cli = new SentryCli();
10-
return cli.releases.proposeVersion().then(version => expect(version).toBeTruthy());
10+
return cli.releases.proposeVersion().then((version) => expect(version).toBeTruthy());
1111
});
1212

1313
describe('with mock', () => {
1414
let cli;
1515
let mockExecute;
1616
beforeAll(() => {
17-
mockExecute = jest.fn(async () => { });
17+
mockExecute = jest.fn(async () => {});
1818
jest.doMock('../../helper', () => ({
1919
...jest.requireActual('../../helper'),
2020
execute: mockExecute,
@@ -52,15 +52,7 @@ describe('SentryCli releases', () => {
5252
test('without projects', async () => {
5353
await cli.releases.uploadSourceMaps('my-version', { include: ['path'] });
5454
expect(mockExecute).toHaveBeenCalledWith(
55-
[
56-
'sourcemaps',
57-
'upload',
58-
'--release',
59-
'my-version',
60-
'path',
61-
'--ignore',
62-
'node_modules',
63-
],
55+
['sourcemaps', 'upload', '--release', 'my-version', 'path', '--ignore', 'node_modules'],
6456
true,
6557
false,
6658
undefined,
@@ -100,17 +92,9 @@ describe('SentryCli releases', () => {
10092
await cli.releases.uploadSourceMaps('my-version', { include: paths });
10193

10294
expect(mockExecute).toHaveBeenCalledTimes(2);
103-
paths.forEach(path =>
95+
paths.forEach((path) =>
10496
expect(mockExecute).toHaveBeenCalledWith(
105-
[
106-
'sourcemaps',
107-
'upload',
108-
'--release',
109-
'my-version',
110-
path,
111-
'--ignore',
112-
'node_modules',
113-
],
97+
['sourcemaps', 'upload', '--release', 'my-version', path, '--ignore', 'node_modules'],
11498
true,
11599
false,
116100
undefined,
@@ -159,25 +143,6 @@ describe('SentryCli releases', () => {
159143
{ silent: false }
160144
);
161145
});
162-
163-
test.each([true, false, 'rejectOnError'])('handles live mode %s', async (live) => {
164-
await cli.releases.uploadSourceMaps('my-version', { include: ['path'], live });
165-
expect(mockExecute).toHaveBeenCalledWith(
166-
[
167-
'sourcemaps',
168-
'upload',
169-
'--release',
170-
'my-version',
171-
'path',
172-
'--ignore',
173-
'node_modules',
174-
],
175-
live,
176-
false,
177-
undefined,
178-
{ silent: false }
179-
);
180-
});
181146
});
182147
});
183148
});

lib/releases/index.js

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -142,11 +142,10 @@ class Releases {
142142
* ext: ['js', 'map', 'jsbundle', 'bundle'], // override file extensions to scan for
143143
* projects: ['node'], // provide a list of projects
144144
* decompress: false // decompress gzip files before uploading
145-
* live: true // whether to inherit stdio to display `sentry-cli` output directly.
146145
* });
147146
*
148147
* @param {string} release Unique name of the release.
149-
* @param {SentryCliUploadSourceMapsOptions & {live?: boolean | 'rejectOnError'}} options Options to configure the source map upload.
148+
* @param {SentryCliUploadSourceMapsOptions} options Options to configure the source map upload.
150149
* @returns {Promise<string[]>} A promise that resolves when the upload has completed successfully.
151150
* @memberof SentryReleases
152151
*/
@@ -193,10 +192,7 @@ class Releases {
193192

194193
return uploadPaths.map((path) =>
195194
// `execute()` is async and thus we're returning a promise here
196-
this.execute(
197-
helper.prepareCommand([...args, path], SOURCEMAPS_SCHEMA, newOptions),
198-
options.live != null ? options.live : true
199-
)
195+
this.execute(helper.prepareCommand([...args, path], SOURCEMAPS_SCHEMA, newOptions), true)
200196
);
201197
});
202198

@@ -252,11 +248,10 @@ class Releases {
252248
/**
253249
* See {helper.execute} docs.
254250
* @param {string[]} args Command line arguments passed to `sentry-cli`.
255-
* @param {boolean | 'rejectOnError'} live can be set to:
256-
* - `true` to inherit stdio to display `sentry-cli` output directly.
257-
* - `false` to not inherit stdio and return the output as a string.
258-
* - `'rejectOnError'` to inherit stdio and reject the promise if the command
251+
* @param {boolean} live can be set to:
252+
* - `true` to inherit stdio and reject the promise if the command
259253
* exits with a non-zero exit code.
254+
* - `false` to not inherit stdio and return the output as a string.
260255
* @returns {Promise<string>} A promise that resolves to the standard output.
261256
*/
262257
async execute(args, live) {

lib/types.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -224,12 +224,12 @@ export interface SentryCliReleases {
224224

225225
uploadSourceMaps(
226226
release: string,
227-
options: SentryCliUploadSourceMapsOptions & { live?: boolean | 'rejectOnError' }
227+
options: SentryCliUploadSourceMapsOptions & { live?: boolean }
228228
): Promise<string[]>;
229229

230230
listDeploys(release: string): Promise<string>;
231231

232232
newDeploy(release: string, options: SentryCliNewDeployOptions): Promise<string>;
233233

234-
execute(args: string[], live: boolean | 'rejectOnError'): Promise<string>;
234+
execute(args: string[], live: boolean): Promise<string>;
235235
}

0 commit comments

Comments
 (0)