Skip to content

Commit

Permalink
fix(build): ignore errors from assume-unchanged MONGOSH-521 (#608)
Browse files Browse the repository at this point in the history
  • Loading branch information
rose-m authored Feb 3, 2021
1 parent 9a3e2ef commit 87d7687
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
11 changes: 11 additions & 0 deletions packages/build/src/npm-packages.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,17 @@ describe('npm-packages', () => {
}
expect.fail('Expected error');
});

it('ignores errors when asked to for ENOENT', () => {
const result = spawnSync('notaprogram', [], { encoding: 'utf8' }, true);
expect(result).to.not.be.undefined;
});

it('ignores errors when asked to for non-zero exit code', () => {
const result = spawnSync('bash', ['-c', 'exit 1'], { encoding: 'utf8' }, true);
expect(result).to.not.be.undefined;
expect(result?.status).to.equal(1);
});
});

describe('bumpNpmPackages', () => {
Expand Down
20 changes: 16 additions & 4 deletions packages/build/src/npm-packages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,30 @@ export interface LernaPackageDescription {
location: string;
}

export function spawnSync(command: string, args: string[], options: SpawnSyncOptionsWithStringEncoding): SpawnSyncReturns<string> {
export function spawnSync(command: string, args: string[], options: SpawnSyncOptionsWithStringEncoding): SpawnSyncReturns<string>;
export function spawnSync(command: string, args: string[], options: SpawnSyncOptionsWithStringEncoding, ignoreErrors: false): SpawnSyncReturns<string>;
export function spawnSync(command: string, args: string[], options: SpawnSyncOptionsWithStringEncoding, ignoreErrors: true): SpawnSyncReturns<string> | undefined;
export function spawnSync(command: string, args: string[], options: SpawnSyncOptionsWithStringEncoding, ignoreErrors = false): SpawnSyncReturns<string> | undefined {
const result = spawn.sync(command, args, options);
if (result.error) {
console.error('spawn.sync returned error', result.error);
console.error(result.stdout);
console.error(result.stderr);
throw new Error(`Failed to spawn ${command}, args: ${args.join(',')}: ${result.error}`);

if (!ignoreErrors) {
throw new Error(`Failed to spawn ${command}, args: ${args.join(',')}: ${result.error}`);
} else {
console.warn('Ignoring error and continuing...');
}
} else if (result.status !== 0) {
console.error('spawn.sync exited with non-zero', result.status);
console.error(result.stdout);
console.error(result.stderr);
throw new Error(`Spawn exited non-zero for ${command}, args: ${args.join(',')}: ${result.status}`);
if (!ignoreErrors) {
throw new Error(`Spawn exited non-zero for ${command}, args: ${args.join(',')}: ${result.status}`);
} else {
console.warn('Ignoring error and continuing...');
}
}
return result;
}
Expand Down Expand Up @@ -138,7 +150,7 @@ export function markBumpedFilesAsAssumeUnchanged(
stdio: 'inherit',
cwd: PROJECT_ROOT,
encoding: 'utf8'
});
}, true);
console.info(`File ${f} is now ${assumeUnchanged ? '' : 'NOT '}assumed to be unchanged`);
});
}

0 comments on commit 87d7687

Please sign in to comment.