Skip to content

Commit 87d7687

Browse files
authored
fix(build): ignore errors from assume-unchanged MONGOSH-521 (#608)
1 parent 9a3e2ef commit 87d7687

File tree

2 files changed

+27
-4
lines changed

2 files changed

+27
-4
lines changed

packages/build/src/npm-packages.spec.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,17 @@ describe('npm-packages', () => {
3636
}
3737
expect.fail('Expected error');
3838
});
39+
40+
it('ignores errors when asked to for ENOENT', () => {
41+
const result = spawnSync('notaprogram', [], { encoding: 'utf8' }, true);
42+
expect(result).to.not.be.undefined;
43+
});
44+
45+
it('ignores errors when asked to for non-zero exit code', () => {
46+
const result = spawnSync('bash', ['-c', 'exit 1'], { encoding: 'utf8' }, true);
47+
expect(result).to.not.be.undefined;
48+
expect(result?.status).to.equal(1);
49+
});
3950
});
4051

4152
describe('bumpNpmPackages', () => {

packages/build/src/npm-packages.ts

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,30 @@ export interface LernaPackageDescription {
1313
location: string;
1414
}
1515

16-
export function spawnSync(command: string, args: string[], options: SpawnSyncOptionsWithStringEncoding): SpawnSyncReturns<string> {
16+
export function spawnSync(command: string, args: string[], options: SpawnSyncOptionsWithStringEncoding): SpawnSyncReturns<string>;
17+
export function spawnSync(command: string, args: string[], options: SpawnSyncOptionsWithStringEncoding, ignoreErrors: false): SpawnSyncReturns<string>;
18+
export function spawnSync(command: string, args: string[], options: SpawnSyncOptionsWithStringEncoding, ignoreErrors: true): SpawnSyncReturns<string> | undefined;
19+
export function spawnSync(command: string, args: string[], options: SpawnSyncOptionsWithStringEncoding, ignoreErrors = false): SpawnSyncReturns<string> | undefined {
1720
const result = spawn.sync(command, args, options);
1821
if (result.error) {
1922
console.error('spawn.sync returned error', result.error);
2023
console.error(result.stdout);
2124
console.error(result.stderr);
22-
throw new Error(`Failed to spawn ${command}, args: ${args.join(',')}: ${result.error}`);
25+
26+
if (!ignoreErrors) {
27+
throw new Error(`Failed to spawn ${command}, args: ${args.join(',')}: ${result.error}`);
28+
} else {
29+
console.warn('Ignoring error and continuing...');
30+
}
2331
} else if (result.status !== 0) {
2432
console.error('spawn.sync exited with non-zero', result.status);
2533
console.error(result.stdout);
2634
console.error(result.stderr);
27-
throw new Error(`Spawn exited non-zero for ${command}, args: ${args.join(',')}: ${result.status}`);
35+
if (!ignoreErrors) {
36+
throw new Error(`Spawn exited non-zero for ${command}, args: ${args.join(',')}: ${result.status}`);
37+
} else {
38+
console.warn('Ignoring error and continuing...');
39+
}
2840
}
2941
return result;
3042
}
@@ -138,7 +150,7 @@ export function markBumpedFilesAsAssumeUnchanged(
138150
stdio: 'inherit',
139151
cwd: PROJECT_ROOT,
140152
encoding: 'utf8'
141-
});
153+
}, true);
142154
console.info(`File ${f} is now ${assumeUnchanged ? '' : 'NOT '}assumed to be unchanged`);
143155
});
144156
}

0 commit comments

Comments
 (0)