Hacker Newsnew | past | comments | ask | show | jobs | submit | lzap's commentslogin

I like how old-school HN comment section does not care about creepy links at all. Or link for that matter.


I was trying to say that eventually, errors in Go distill to strings. Of course the type which represents errors can be anything, I thought it is obvious and it is also mentioned in the introduction section which you may have skipped.


Great example, should have known this one.


As I said in the article, the example is simplified. As you point out, incorporating the HTTP code into the error and using errors.As is much better way of doing that:

"Obviously, the common HTTP status codes could easily be a new error type (based on int type) so the actual code could be easily extracted via errors.As, but I want to keep the example simple."


In the blogpost I specifically wrote "There is no (named) interface in the standard library..." because I was aware of the function you point out. Rather than unexported interface, I would probably call that an "anonymous interface".

Anyway, now that I read that, I should probably skip this fact and just keep the example interface. It is not uncommon practice in Go to make "copies" of interfaces to avoid extra dependency (or cyclic dependency).


Sorry, that shot right past me. The article sounded, to me anyway, impressed the interface didn't exist. Seeing the cast/check against the anonymous interface left me unimpressed haha.

> It is not uncommon practice in Go to make "copies" of interfaces to avoid extra dependency (or cyclic dependency).

I hadn't really noticed but my exposure to the source is spotty. See what they are doing there and can imagine why, it just irks me.

There are now implicit, "standard" shapes for Error that don't have named, exported interfaces and presumably anyone wanting to write code around both Unwrap shapes will need to reach for the same techniques to suss out what they are dealing with..


Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: