logoalt Hacker News

pikzellast Tuesday at 6:35 PM3 repliesview on HN

They still haven't solved shadowing.

  a, err := foo()
  b, err := bar()
  if err != nil { // oops, forgot to handle foo()'s err }
This is the illusion of safe error handling.

Replies

AnimalMuppetlast Tuesday at 6:37 PM

I would be astonished if there isn't an automated tool to check for that at the push of a button. I would be mildly surprised if there isn't a compiler flag to check for it.

show 3 replies
catlifeonmarslast Wednesday at 2:31 AM

I’m surprised I don’t see this mentioned more. This is spooky action at a distance at its worst. And it’s not even limited to error handling. Any multi value assignment works like this.

_bentonlast Tuesday at 9:05 PM

It's fairly obvious when writing Go that `err` is being shadowed and needs to be checked after each expression. You should be wrapping them anyways!