News for hackers. Stuff that matters.
Re:NPM proxy users receiving ERR 418 I'm a teapot by hn_throwaway_99 on Monday May 28, 2018 @10:27PM (#17176026)
Sure, but why is anything in the chain returning the 418 "I'm a teapot" error message?

My guess is someone wanted to use some code for "I don't really know what this error is", saw the 418 and thought "that's cute!"

Be careful, "cuteness" and "cleverness" has a way of biting you in the behind.

Re:NPM proxy users receiving ERR 418 I'm a teapot by jwalton on Tuesday May 29, 2018 @12:10AM (#17176430)
As per https://tools.ietf.org/html/rfc2324, the server is throwing 418 because it is a teapot, and can't brew coffee. Perhaps this is a coffeescript related problem.
Re:NPM proxy users receiving ERR 418 I'm a teapot by fyfy18 on Tuesday May 29, 2018 @12:46AM (#17176582)
I’m not sure if this is really compliant to that spec either. It states that error code should be returned when attempting to brew coffee - which means the BREW or POST method is used - but this is using the GET method.
Re:NPM proxy users receiving ERR 418 I'm a teapot by stephengillie on Tuesday May 29, 2018 @06:01AM (#17177797)
Has a BREW call been used? The spec might not support out of order operations. That should be tried before any further GET attempts against the coffee interface.
Re:NPM proxy users receiving ERR 418 I'm a teapot by hluska on Monday May 28, 2018 @10:42PM (#17176086)
Ha! I used to use 418 as my "everything is completely fucked and there's no way everything will ever get that fucked, so this is the best code possible" status code.

It took about a year for me to internalize that things will often be that fucked. :)

Re:NPM proxy users receiving ERR 418 I'm a teapot by simplecomplex on Monday May 28, 2018 @11:03PM (#17176169)
500 “Internal Server Error” is the code you should be using for generic server errors.
Re:NPM proxy users receiving ERR 418 I'm a teapot by curun1r on Tuesday May 29, 2018 @12:02AM (#17176397)
It's important to say why that's the correct error code. In this case, it's because 5xx errors can be retried in the future whereas 4xx errors tell the client that any retries will receive the same response.
Re:NPM proxy users receiving ERR 418 I'm a teapot by boomlinde on Tuesday May 29, 2018 @03:39AM (#17177159)
In general, this is wrong. 4xx status may be retried, achieving different results each time. This makes sense with for example status 409 and 429, where this is definitely expected, or 404 since resources may be added or removed at any time independent of any single client, or 402 and 403 which may change out of band.

Conversely, there are 5xx statuses that you shouldn't expect to change with each request, for example 505 (HTTP version not supported) or, really, 500 in some cases.

There's AFAIK no standardized strategy to deal with the different status code. Instead it's important to get the status code right to as accurately as possible describe the error to the client. The server never tells the client what to do; it tells it what went wrong so that the client can deal with the error at its own discretion. In this case the server told he client that it was a teapot when what actually happened was an internal server error. That's wrong because it's wrong, not because every client will or even should deal with either of these errors in a predictable way.

Re:NPM proxy users receiving ERR 418 I'm a teapot by curun1r on Tuesday May 29, 2018 @04:18PM (#17182610)
> There's AFAIK no standardized strategy to deal with the different status code

While I was a bit too over-broad in my generalizations of 4xx vs 5xx status codes when it comes to retries, the gist is still the same. The specification does specifically call out when it's okay to retry and when it isn't. And it also specifically calls out when it's okay for intermediate servers and browsers to cache responses and when it isn't. In the case being discussed, 500 is specifically the correct error code because it cannot be cached and can be retried. That's not the case for 409 or 429, which either cannot be retried automatically (409) or can be cached (429). 402 is, IIRC, underspecified and shouldn't be used. 403 specifically states that the request should not be retried.

It's important to make a distinction between the user/application and the user agent when we talk about retries. The user agent is the program or library that implements the HTTP spec. You seem to be talking about the former, who is always capable of retrying a request when they feel circumstances have changed enough for the request to succeed. But user agents are intentionally dumber. They can't resolve conflicts, fix permissions or do anything outside of the logic dictated by the spec. And they have much more limited license to retry 4xx responses or cache 5xx responses.

Re:NPM proxy users receiving ERR 418 I'm a teapot by eropple on Tuesday May 29, 2018 @12:17AM (#17176459)
This is honored more in the breach than the observance at times, though, particularly with 404.
Re:NPM proxy users receiving ERR 418 I'm a teapot by hluska on Tuesday May 29, 2018 @02:29AM (#17176917)
I'm sorry that I wasn't more clear. The person I was replying to aptly wrote "'cuteness' and 'cleverness' has a way of biting you in the behind", and I was agreeing with/adding to that comment. I've been guilty of cleverness and sure enough, it has usually found a way to get me in the end.

Today, in similar situations, I'd return a 500 with a message in the body.

Re:NPM proxy users receiving ERR 418 I'm a teapot by K0nserv on Tuesday May 29, 2018 @05:06AM (#17177546)
No it's not since this is a error on the client's side it should be a 4xx code, probably not 418 though.
Re:NPM proxy users receiving ERR 418 I'm a teapot by 49bc on Monday May 28, 2018 @11:09PM (#17176188)
Yes a 500. Not sure how anything else would ever pass the smell test of even a lazy pull request.
Re:NPM proxy users receiving ERR 418 I'm a teapot by sofaofthedamned on Tuesday May 29, 2018 @03:04AM (#17177047)
I've seen the teapot error used when the internal route of a request was circuitous (many servers involved) and a 500 could have come form anywhere. It was used as a canary, and only on this codebase which was bought-in and absolutely awful.
Re:NPM proxy users receiving ERR 418 I'm a teapot by yeukhon on Tuesday May 29, 2018 @02:12AM (#17176860)
Actually, 503 is better in this case. Internally it shlkld report 500.
Re:NPM proxy users receiving ERR 418 I'm a teapot by astura on Monday May 28, 2018 @11:12PM (#17176202)
500 is the correct error code to use in that case.
Re:NPM proxy users receiving ERR 418 I'm a teapot by jmvoodoo on Monday May 28, 2018 @11:58PM (#17176374)
It's 4xx so it should be used only to represent an issue with the request/client, not the server :)
Re:NPM proxy users receiving ERR 418 I'm a teapot by rejschaap on Tuesday May 29, 2018 @04:09AM (#17177263)
> Sure, but why is anything in the chain returning the 418 "I'm a teapot" error message?

My best guess? The request ended up at a teapot and the poor thing was asked to do something that no teapot has ever done before.

Re:NPM proxy users receiving ERR 418 I'm a teapot by nmjohn on Monday May 28, 2018 @10:47PM (#17176106)
> Be careful, "cuteness" and "cleverness" has a way of biting you in the behind.

Generally speaking I tend to agree, but in this specific case how is sending a 418 "biting you in the behind" worse than sending a more proper 500 error? (Or perhaps a 400? Hard to say exactly, feels like the server is having unexpected errors since it cannot properly parse the hostname.)

Re:NPM proxy users receiving ERR 418 I'm a teapot by reificator on Monday May 28, 2018 @10:53PM (#17176134)
If I'm doing quick generic error handling, I'm going to assume anything in the 500 range is a server issue and display an error of the sort. If it's in the 400 range I'm going to handle the common ones and then assume it's the client's or user's fault. (And of course a user fault is really a client validation fault.)

So yes, returning a 4XX for a 5XX is problematic.

Re:NPM proxy users receiving ERR 418 I'm a teapot by nmjohn on Monday May 28, 2018 @11:03PM (#17176168)
But is that relevant to _this specific_ case? The problem is not 3rd party clients, it's the npm client itself - so I don't know how error handling is relevant? (In the general case, yes of course it is, but in this and the parent comment I'm specifically talking about issues in only the narrow use case here.)
Re:NPM proxy users receiving ERR 418 I'm a teapot by tedivm on Tuesday May 29, 2018 @02:24AM (#17176904)
The error was on the server side, not the client side. The server was not following the HTTP spec. The fact that it was server side was why they were able to fix this so quickly.

Since it was a server side error, and the issue was not a client side one, the 500 error code is most appropriate. The fact that the npm client itself is the first one to trigger this error is not the issue here, as it could have just as easily been yarn or another client. Following standards are important, and we weren't trying to make tea.

Re:NPM proxy users receiving ERR 418 I'm a teapot by reificator on Monday May 28, 2018 @11:07PM (#17176178)
Being first party doesn't mean it's the same person/team writing both sides.

And error handling is always relevant.

Re:NPM proxy users receiving ERR 418 I'm a teapot by nonconvergent on Tuesday May 29, 2018 @09:06AM (#17178761)
The type of status/error matters. It's how your communicate, server to client.

Think about your normal interactions with problem solving as a team. What's more useful, a teammate who tells you when there's a problem what the problem is or a teammate who hides things, obfuscates, and makes random jokes?

400 tells you asked in a way that wasn't understood.

401 says you're unauthorized and 403 says you're not allowed (similar but potentially different implications, not my favorite nuance but it's a common example that might come up)

504 says there's a problem communicating between the two of you.

404 says that your data doesn't exist.

500 says the server is having problems doing the thing and it's completely out of your hands.

418 says "I'm a teapot"

What's more useful data?

Re:NPM proxy users receiving ERR 418 I'm a teapot by boomlinde on Tuesday May 29, 2018 @03:52AM (#17177198)
> Or perhaps a 400?

Well ideally some 5xx code because it's a server error. I personally think servers should default to 500 if there is an uncaught or unhandled error condition.

Re:NPM proxy users receiving ERR 418 I'm a teapot by TheDong on Monday May 28, 2018 @11:22PM (#17176236)
In general, proxies and other third party clients will consider 4xx errors (edit: un)retriable.

That's one simple obvious difference.

Re:NPM proxy users receiving ERR 418 I'm a teapot by reificator on Tuesday May 29, 2018 @12:19AM (#17176471)
Do you mean 5XX? 4XX errors generally cannot be retried with a different result.
Re:NPM proxy users receiving ERR 418 I'm a teapot by nneonneo on Tuesday May 29, 2018 @12:00AM (#17176380)
The origin server (registry.npmjs.org) is the one throwing the 418, so they're primarily to blame. Some intermediate proxy server has decided to send a somewhat unusual Host header (registry.npmjs.org:443 instead of the usual registry.npmjs.org), and the registry server barfs up a 418 in response.
Re:NPM proxy users receiving ERR 418 I'm a teapot by nonconvergent on Tuesday May 29, 2018 @08:56AM (#17178682)
There's nothing clever about returning the wrong error. That's anti-clever.