Skip to content

Commit 84b1d08

Browse files
authored
feat(cli-repl): mark exceptions from mongoshrc as such MONGOSH-911 (#1027)
1 parent 4992468 commit 84b1d08

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

packages/cli-repl/src/cli-repl.spec.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,14 @@ describe('CliRepl', () => {
388388
await cliRepl.start('', {});
389389
expect(output).to.include('reached five');
390390
});
391+
392+
it('if an exception is thrown, indicates that it comes from mongoshrc', async() => {
393+
await fs.writeFile(path.join(tmpdir.path, '.mongoshrc.js'), 'throw new Error("bananas")');
394+
cliRepl = new CliRepl(cliReplOptions);
395+
await cliRepl.start('', {});
396+
expect(output).to.include('Error while running ~/.mongoshrc.js:');
397+
expect(output).to.include('Error: bananas');
398+
});
391399
});
392400

393401
context('files loaded from command line', () => {

packages/cli-repl/src/cli-repl.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,7 @@ class CliRepl {
240240
this.bus.emit('mongosh:mongoshrc-load');
241241
await this.mongoshRepl.loadExternalFile(mongoshrcPath);
242242
} catch (err) {
243+
this.output.write(this.clr('Error while running ~/.mongoshrc.js:\n', ['bold', 'yellow']));
243244
this.output.write(this.mongoshRepl.writer(err) + '\n');
244245
}
245246
return;

0 commit comments

Comments
 (0)