Skip to content

Commit 5b117c5

Browse files
Log stacktrace on failure (#176)
1 parent fc516e1 commit 5b117c5

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

source/cli.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,11 @@ const cli = meow(`
5454
throw new Error(formatter(diagnostics));
5555
}
5656
} catch (error: unknown) {
57-
if (error && typeof (error as Error).message === 'string') {
58-
console.error((error as Error).message);
57+
const potentialError = error as Error | undefined;
58+
const errorMessage = potentialError?.stack ?? potentialError?.message;
59+
60+
if (errorMessage) {
61+
console.error(`Error running tsd: ${errorMessage}`);
5962
}
6063

6164
process.exit(1);

source/test/cli.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,3 +95,13 @@ test('cli typings and files flags', async t => {
9595
t.is(exitCode, 1);
9696
t.true(stderr.includes('✖ 5:19 Argument of type number is not assignable to parameter of type string.'));
9797
});
98+
99+
test('tsd logs stacktrace on failure', async t => {
100+
const {exitCode, stderr, stack} = await t.throwsAsync<ExecaError>(execa('../../../cli.js', {
101+
cwd: path.join(__dirname, 'fixtures/empty-package-json')
102+
}));
103+
104+
t.is(exitCode, 1);
105+
t.true(stderr.includes('Error running tsd: JSONError: Unexpected end of JSON input while parsing empty string'));
106+
t.truthy(stack);
107+
});

source/test/fixtures/empty-package-json/package.json

Whitespace-only changes.

0 commit comments

Comments
 (0)