3 ms·
The _, err cascade is a nuisance when refactoring; I have gotten into the habit of throwing a var err error at the top of any function with a number of possible
by swdunlop 14y ago
The _, err cascade is a nuisance when refactoring; I have gotten into the habit of throwing a var err error at the top of any function with a number of possible error results -- it also makes a handy notation that "here there be glue code."
Of course, where there's "_, err = ...", "if err != nil" returns are rarely far behind. :)
- NateDad 14y agoif you use the standard if _, err := foo(); err != nil { then the err variable's scope is limited to the if statement (usually correct), and you can then move that if statement where ever you want and it will stay intact, and will not interfere with the external code.