Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix error messages when tsd fails #189

Merged
merged 2 commits into from
Mar 21, 2023

Conversation

tommy-mitchell
Copy link
Contributor

Similar to #182, tsd will also display an error stack on failure (even if it didn't crash), e.g. when no index.d.ts is found:

Error running tsd:
Error: The type definition \`index.d.ts\` does not exist at \`.../fixtures/no-tsd/index.d.ts\`. Is the path correct? Create one and try again.
    at .../lib/index.js:31:15
    at Generator.next (<anonymous>)
    at fulfilled (.../lib/index.js:5:58)

This should only show the error message:

The type definition \`index.d.ts\` does not exist at \`.../fixtures/no-tsd/index.d.ts\`. Is the path correct? Create one and try again.

This PR adds a custom TsdError to differentiate between the two cases:

try {
    // ... run tsd
} catch (error: unknown) {
    const potentialError = error as Error | undefined;

    if (potentialError instanceof TsdError) {
        exit(potentialError.message);
    }

    const errorMessage = potentialError?.stack ?? potentialError?.message ?? 'tsd unexpectedly crashed.';

    exit(`Error running tsd:\n${errorMessage}`);
}

@sindresorhus sindresorhus merged commit c785d9c into tsdjs:main Mar 21, 2023
@tommy-mitchell
Copy link
Contributor Author

@sindresorhus could you put out a patch release for this?

@sindresorhus
Copy link
Collaborator

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants