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

Meaningful error message on malformed registry response #1356

Merged
merged 2 commits into from
Oct 24, 2016
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/resolvers/registries/npm-resolver.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ export default class NpmResolver extends RegistryResolver {
static registry = 'npm';

static async findVersionInRegistryResponse(config: Config, range: string, body: RegistryResponse): Promise<Manifest> {
if (!body['dist-tags']) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this check feels very loose. I wonder if we can do better or if this is the best we can do...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was thinking the same thing, but I believe this is possibly the best indicator of a well-formed response, given what we want. Definitely open to suggestions, but I was specifically trying to avoid an error slightly lower down where body['dist-tags'] is undefined.

throw new MessageError(`Received malformed response from registry. The registry may be down.`);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs to use this.reporter.lang, look for other uses in the codebase to see what I mean

}

if (range in body['dist-tags']) {
range = body['dist-tags'][range];
}
Expand Down