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

Meaningful error message on malformed registry response #1356

merged 2 commits into from
Oct 24, 2016

Conversation

rivertam
Copy link
Contributor

Summary

When the yarn DNS failed to resolve today, a malformed response from the registry caused a cryptic error (see #1348) rather than a meaningful message.

Sorry for no test plan; this is a simple commit, but I wouldn't know how to reproduce it. npm test still works, so it doesn't break anything. =)

@@ -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']) {
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

@@ -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.

@@ -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']) {
throw new MessageError(config.reporter.lang('malformedRegistryResponse'));
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@thejameskyle Looking better, hopefully? Thanks for the review =)

@@ -1,5 +1,5 @@
HTTP/1.1 200 OK
Date: Wed, 19 Oct 2016 13:30:48 GMT
Date: Mon, 24 Oct 2016 13:03:20 GMT
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 think this should be in the .gitignore, but I'm not sure what the generalized entry would be.

@SvenWalter
Copy link

Currently I'm facing the same issue. Is there any time frame when it will be part of a official release? Thanks ... and great work!

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.

5 participants